From 00d69986da83a74f6f5731c80f8dd09fde95d19a Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 22 Jun 2020 16:03:55 -0500 Subject: [PATCH 1/5] 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 Signed-off-by: Eric Blake Message-Id: <20200622210355.414941-1-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- 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'; } From 8cf58a49f883f089e7d4b6e19acc987085d024fd Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 20 Apr 2020 12:53:07 -0500 Subject: [PATCH 2/5] hax: Fix setting of FD_CLOEXEC Blindly setting FD_CLOEXEC without a read-modify-write will inadvertently clear any other intentionally-set bits, such as a proposed new bit for designating a fd that must behave in 32-bit mode. Use our wrapper function instead of an incorrect hand-rolled version. Signed-off-by: Eric Blake Message-Id: <20200420175309.75894-2-eblake@redhat.com> Reviewed-by: Colin Xu --- target/i386/hax-posix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/target/i386/hax-posix.c b/target/i386/hax-posix.c index 3bad89f13337..5f9d1b803dec 100644 --- a/target/i386/hax-posix.c +++ b/target/i386/hax-posix.c @@ -23,7 +23,7 @@ hax_fd hax_mod_open(void) fprintf(stderr, "Failed to open the hax module\n"); } - fcntl(fd, F_SETFD, FD_CLOEXEC); + qemu_set_cloexec(fd); return fd; } @@ -147,7 +147,7 @@ hax_fd hax_host_open_vm(struct hax_state *hax, int vm_id) fd = open(vm_name, O_RDWR); g_free(vm_name); - fcntl(fd, F_SETFD, FD_CLOEXEC); + qemu_set_cloexec(fd); return fd; } @@ -200,7 +200,7 @@ hax_fd hax_host_open_vcpu(int vmid, int vcpuid) if (fd < 0) { fprintf(stderr, "Failed to open the vcpu devfs\n"); } - fcntl(fd, F_SETFD, FD_CLOEXEC); + qemu_set_cloexec(fd); return fd; } From a1a7f56cdd1ddc99fcd1078c9285849aaaaaeca9 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Wed, 1 Jul 2020 13:53:27 +0300 Subject: [PATCH 3/5] iotests: QemuIoInteractive: use qemu_io_args_no_fmt The only user (iotest 205) of QemuIoInteractive provides -f argument, so it's a bit inefficient to use qemu_io_args, which contains -f too. And we are going to add one more test, which wants to specify -f by hand. Let's use qemu_io_args_no_fmt. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20200701105331.121670-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/iotests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index f1e0733dda05..109fb3884a26 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -212,7 +212,7 @@ def get_virtio_scsi_device(): class QemuIoInteractive: def __init__(self, *args): - self.args = qemu_io_args + list(args) + self.args = qemu_io_args_no_fmt + list(args) self._p = subprocess.Popen(self.args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, From 1f4b774a6444575b86f27b17d3d01e4f41df6581 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Wed, 1 Jul 2020 13:53:28 +0300 Subject: [PATCH 4/5] iotests.py: QemuIoInteractive: print output on failure Make it simpler to debug when qemu-io fails due to wrong arguments or environment. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20200701105331.121670-3-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/iotests.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 109fb3884a26..2a08fea3c9ec 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -217,7 +217,13 @@ def __init__(self, *args): stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) - assert self._p.stdout.read(9) == 'qemu-io> ' + out = self._p.stdout.read(9) + if out != 'qemu-io> ': + # Most probably qemu-io just failed to start. + # Let's collect the whole output and exit. + out += self._p.stdout.read() + self._p.wait(timeout=1) + raise ValueError(out) def close(self): self._p.communicate('q\n') From df0e032b6196934b2b12180a6a05aa8b7e6553fc Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Wed, 1 Jul 2020 13:53:30 +0300 Subject: [PATCH 5/5] iotests.py: filter_testfiles(): filter SOCK_DIR too Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20200701105331.121670-5-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/iotests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 2a08fea3c9ec..8b760405ee72 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -345,8 +345,9 @@ def filter_qmp(qmsg, filter_fn): return qmsg def filter_testfiles(msg): - prefix = os.path.join(test_dir, "%s-" % (os.getpid())) - return msg.replace(prefix, 'TEST_DIR/PID-') + pref1 = os.path.join(test_dir, "%s-" % (os.getpid())) + pref2 = os.path.join(sock_dir, "%s-" % (os.getpid())) + return msg.replace(pref1, 'TEST_DIR/PID-').replace(pref2, 'SOCK_DIR/PID-') def filter_qmp_testfiles(qmsg): def _filter(_key, value):