[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[qemu-xen staging] nbd: Avoid off-by-one in long export name truncation



commit 00d69986da83a74f6f5731c80f8dd09fde95d19a
Author:     Eric Blake <eblake@xxxxxxxxxx>
AuthorDate: Mon Jun 22 16:03:55 2020 -0500
Commit:     Eric Blake <eblake@xxxxxxxxxx>
CommitDate: Mon Jul 13 09:01:01 2020 -0500

    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: 5c86bdf12089
    Reported-by: Max Reitz <mreitz@xxxxxxxxxx>
    Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
    Message-Id: <20200622210355.414941-1-eblake@xxxxxxxxxx>
    Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@xxxxxxxxxxxxx>
---
 block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/nbd.c b/block/nbd.c
index c297336ffc..65a4f56924 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';
     }
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.