* [PATCH] Btrfs: fix snprintf usage by send's gen_unique_name
@ 2014-01-21 23:36 Filipe David Borba Manana
2014-01-22 11:31 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Filipe David Borba Manana @ 2014-01-21 23:36 UTC (permalink / raw)
To: linux-btrfs; +Cc: Filipe David Borba Manana
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>
---
fs/btrfs/send.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 84aed2f..27edc5e 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -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 */
--
1.7.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Btrfs: fix snprintf usage by send's gen_unique_name
2014-01-21 23:36 [PATCH] Btrfs: fix snprintf usage by send's gen_unique_name Filipe David Borba Manana
@ 2014-01-22 11:31 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2014-01-22 11:31 UTC (permalink / raw)
To: Filipe David Borba Manana; +Cc: linux-btrfs
On Tue, Jan 21, 2014 at 11:36:38PM +0000, Filipe David Borba Manana wrote:
> 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>
JFYI, I have a patch to do the same plus cleans the code around, but
it's part of a bigger series that's in testing atm, so I haven't sent it
yet.
Consider it
Reviewed-by: David Sterba <dsterba@suse.cz>
I'll update my version.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-01-22 11:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-21 23:36 [PATCH] Btrfs: fix snprintf usage by send's gen_unique_name Filipe David Borba Manana
2014-01-22 11:31 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox