[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 1/5] nbd: Avoid off-by-one in long export name truncation
From: |
Eric Blake |
Subject: |
[PULL 1/5] nbd: Avoid off-by-one in long export name truncation |
Date: |
Mon, 13 Jul 2020 09:21:02 -0500 |
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>
---
block/nbd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/nbd.c b/block/nbd.c
index c297336ffc5f..65a4f56924ec 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -2002,7 +2002,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
- [PULL 0/5] NBD patches for 2020-07-13, Eric Blake, 2020/07/13
- [PULL 1/5] nbd: Avoid off-by-one in long export name truncation,
Eric Blake <=
- [PULL 3/5] iotests: QemuIoInteractive: use qemu_io_args_no_fmt, Eric Blake, 2020/07/13
- [PULL 4/5] iotests.py: QemuIoInteractive: print output on failure, Eric Blake, 2020/07/13
- [PULL 5/5] iotests.py: filter_testfiles(): filter SOCK_DIR too, Eric Blake, 2020/07/13
- [PULL 2/5] hax: Fix setting of FD_CLOEXEC, Eric Blake, 2020/07/13
- Re: [PULL 0/5] NBD patches for 2020-07-13, Peter Maydell, 2020/07/14