[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/64] block: Raise an error when backing file parameter is an emp
From: |
Kevin Wolf |
Subject: |
[PULL 01/64] block: Raise an error when backing file parameter is an empty string |
Date: |
Mon, 7 Sep 2020 13:08:33 +0200 |
From: Connor Kuehl <ckuehl@redhat.com>
Providing an empty string for the backing file parameter like so:
qemu-img create -f qcow2 -b '' /tmp/foo
allows the flow of control to reach and subsequently fail an assert
statement because passing an empty string to
bdrv_get_full_backing_filename_from_filename()
simply results in NULL being returned without an error being raised.
To fix this, let's check for an empty string when getting the value from
the opts list.
Reported-by: Attila Fazekas <afazekas@redhat.com>
Fixes: https://bugzilla.redhat.com/1809553
Signed-off-by: Connor Kuehl <ckuehl@redhat.com>
Message-Id: <20200813134722.802180-1-ckuehl@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 4 ++++
tests/qemu-iotests/049 | 4 ++++
tests/qemu-iotests/049.out | 5 +++++
3 files changed, 13 insertions(+)
diff --git a/block.c b/block.c
index 2ba76b2c36..b204b93a2e 100644
--- a/block.c
+++ b/block.c
@@ -6119,6 +6119,10 @@ void bdrv_img_create(const char *filename, const char
*fmt,
"same filename as the backing file");
goto out;
}
+ if (backing_file[0] == '\0') {
+ error_setg(errp, "Expected backing file name, got empty string");
+ goto out;
+ }
}
backing_fmt = qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT);
diff --git a/tests/qemu-iotests/049 b/tests/qemu-iotests/049
index 051a1c79e0..82b1e6c202 100755
--- a/tests/qemu-iotests/049
+++ b/tests/qemu-iotests/049
@@ -119,6 +119,10 @@ test_qemu_img create -f $IMGFMT -o
compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M
test_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG"
64M
test_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG"
64M
+echo "== Expect error when backing file name is empty string =="
+echo
+test_qemu_img create -f $IMGFMT -b '' $TEST_IMG 1M
+
# success, all done
echo "*** done"
rm -f $seq.full
diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out
index a7e220830d..b1d8fd9107 100644
--- a/tests/qemu-iotests/049.out
+++ b/tests/qemu-iotests/049.out
@@ -209,4 +209,9 @@ qemu-img create -f qcow2 -o compat=0.10,lazy_refcounts=on
TEST_DIR/t.qcow2 64M
Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off
compression_type=zlib size=67108864 compat=0.10 lazy_refcounts=on
refcount_bits=16
qemu-img: TEST_DIR/t.qcow2: Lazy refcounts only supported with compatibility
level 1.1 and above (use version=v3 or greater)
+== Expect error when backing file name is empty string ==
+
+qemu-img create -f qcow2 -b TEST_DIR/t.qcow2 1M
+qemu-img: TEST_DIR/t.qcow2: Expected backing file name, got empty string
+
*** done
--
2.25.4
- [PULL 00/64] Block layer patches, Kevin Wolf, 2020/09/07
- [PULL 02/64] block/nvme: Replace magic value by SCALE_MS definition, Kevin Wolf, 2020/09/07
- [PULL 04/64] block/nvme: Let nvme_create_queue_pair() fail gracefully, Kevin Wolf, 2020/09/07
- [PULL 03/64] block/nvme: Avoid further processing if trace event not enabled, Kevin Wolf, 2020/09/07
- [PULL 01/64] block: Raise an error when backing file parameter is an empty string,
Kevin Wolf <=
- [PULL 06/64] block/nvme: Improve error message when IO queue creation failed, Kevin Wolf, 2020/09/07
- [PULL 07/64] block/nvme: Use common error path in nvme_add_io_queue(), Kevin Wolf, 2020/09/07
- [PULL 05/64] block/nvme: Define INDEX macros to ease code review, Kevin Wolf, 2020/09/07
- [PULL 09/64] block/nvme: Use union of NvmeIdCtrl / NvmeIdNs structures, Kevin Wolf, 2020/09/07
- [PULL 10/64] block/nvme: Replace qemu_try_blockalign0 by qemu_try_blockalign/memset, Kevin Wolf, 2020/09/07
- [PULL 11/64] block/nvme: Replace qemu_try_blockalign(bs) by qemu_try_memalign(pg_sz), Kevin Wolf, 2020/09/07
- [PULL 12/64] block/nvme: Simplify nvme_init_queue() arguments, Kevin Wolf, 2020/09/07
- [PULL 13/64] block/nvme: Replace BDRV_POLL_WHILE by AIO_WAIT_WHILE, Kevin Wolf, 2020/09/07
- [PULL 08/64] block/nvme: Rename local variable, Kevin Wolf, 2020/09/07
- [PULL 14/64] block/nvme: Simplify nvme_create_queue_pair() arguments, Kevin Wolf, 2020/09/07