qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nbd: Avoid off-by-one in long export name truncation
@ 2020-06-22 21:03 Eric Blake
  2020-06-23  7:20 ` Vladimir Sementsov-Ogievskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Blake @ 2020-06-22 21:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, vsementsov, open list:Network Block Dev..., Max Reitz

When snprintf returns the same value as the buffer size, the final
byte was truncated to ensure a NUL terminator.  Fortunately, such long
export names are unusual enough, with no real impact other than what
is displayed to the user.

Fixes: 5c86bdf12089
Reported-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
 block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/nbd.c b/block/nbd.c
index eed160c5cda1..8301fcac0589 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -2009,7 +2009,7 @@ static void nbd_refresh_filename(BlockDriverState *bs)
         len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
                        "nbd://%s:%s", host, port);
     }
-    if (len > sizeof(bs->exact_filename)) {
+    if (len >= sizeof(bs->exact_filename)) {
         /* Name is too long to represent exactly, so leave it empty. */
         bs->exact_filename[0] = '\0';
     }
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-23  7:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-22 21:03 [PATCH] nbd: Avoid off-by-one in long export name truncation Eric Blake
2020-06-23  7:20 ` Vladimir Sementsov-Ogievskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).