Commit f74b86d8 authored by Filipe David Borba Manana's avatar Filipe David Borba Manana Committed by Chris Mason

Btrfs: fix snprintf usage by send's gen_unique_name

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: default avatarFilipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.cz>
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent c41570c9
...@@ -1336,7 +1336,7 @@ static int gen_unique_name(struct send_ctx *sctx, ...@@ -1336,7 +1336,7 @@ static int gen_unique_name(struct send_ctx *sctx,
return -ENOMEM; return -ENOMEM;
while (1) { while (1) {
len = snprintf(tmp, sizeof(tmp) - 1, "o%llu-%llu-%llu", len = snprintf(tmp, sizeof(tmp), "o%llu-%llu-%llu",
ino, gen, idx); ino, gen, idx);
if (len >= sizeof(tmp)) { if (len >= sizeof(tmp)) {
/* should really not happen */ /* should really not happen */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment