Commit 00d69986 authored by Eric Blake's avatar Eric Blake
Browse files

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: 5c86bdf1
Reported-by: default avatarMax Reitz <mreitz@redhat.com>
Signed-off-by: default avatarEric Blake <eblake@redhat.com>
Message-Id: <20200622210355.414941-1-eblake@redhat.com>
Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
parent 00ce6c36
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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';
    }