diff mbox series

[40/77] nbd: Avoid off-by-one in long export name truncation

Message ID 20200903205935.27832-41-mdroth@linux.vnet.ibm.com
State New
Headers show
Series [01/77] hostmem: don't use mbind() if host-nodes is empty | expand

Commit Message

Michael Roth Sept. 3, 2020, 8:58 p.m. UTC
From: Eric Blake <eblake@redhat.com>

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>
Message-Id: <20200622210355.414941-1-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
(cherry picked from commit 00d69986da83a74f6f5731c80f8dd09fde95d19a)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/block/nbd.c b/block/nbd.c
index bfc0be6af6..bf3fbebfa0 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -2011,7 +2011,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';
     }