]> Pileus Git - ~andy/linux/commitdiff
Btrfs: fix snprintf usage by send's gen_unique_name
authorFilipe David Borba Manana <fdmanana@gmail.com>
Tue, 21 Jan 2014 23:36:38 +0000 (23:36 +0000)
committerChris Mason <clm@fb.com>
Tue, 28 Jan 2014 21:20:43 +0000 (13:20 -0800)
The buffer size argument passed to snprintf must account for the
trailing null byte added by snprintf, and it returns a value >= then
sizeof(buffer) when the string can't fit in the buffer.

Since our buffer has a size of 64 characters, and the maximum orphan
name we can generate is 63 characters wide, we must pass 64 as the
buffer size to snprintf, and not 63.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/send.c

index aa60cbe7066ca8f3b720cca8e25aec6e0e046c8f..fc1f0abb8fe463ae3d68f7fbe84f5aab47cf1200 100644 (file)
@@ -1336,7 +1336,7 @@ static int gen_unique_name(struct send_ctx *sctx,
                return -ENOMEM;
 
        while (1) {
-               len = snprintf(tmp, sizeof(tmp) - 1, "o%llu-%llu-%llu",
+               len = snprintf(tmp, sizeof(tmp), "o%llu-%llu-%llu",
                                ino, gen, idx);
                if (len >= sizeof(tmp)) {
                        /* should really not happen */