Skip to content

Commit 00d6998

Browse files
committed
nbd: Avoid off-by-one in long export name truncation
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: 5c86bdf Reported-by: Max Reitz <[email protected]> Signed-off-by: Eric Blake <[email protected]> Message-Id: <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
1 parent 00ce6c3 commit 00d6998

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

block/nbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ static void nbd_refresh_filename(BlockDriverState *bs)
20022002
len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
20032003
"nbd://%s:%s", host, port);
20042004
}
2005-
if (len > sizeof(bs->exact_filename)) {
2005+
if (len >= sizeof(bs->exact_filename)) {
20062006
/* Name is too long to represent exactly, so leave it empty. */
20072007
bs->exact_filename[0] = '\0';
20082008
}

0 commit comments

Comments
 (0)