Skip to contentSkip to conversation

vmdk: Check VMFS extent line field number

PATCH Applied Fam Zheng 2 participants 2 messages Dec 9, 2013 – Dec 19, 2013 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 vmdk: Check VMFS extent line field number

VMFS extent line in description file should be with 4 fields:

RW <size> VMFS "file-name.vmdk"

Check the number explicitly and report error if offset is appended as FLAT, which should be invalid format.

---
 block/vmdk.c               |  9 +++++++--
 tests/qemu-iotests/059     | 14 ++++++++++++++
 tests/qemu-iotests/059.out |  5 +++++
 3 files changed, 26 insertions(+), 2 deletions(-)
block/vmdk.c +7 -2
index 0734bc2..7917ad0 100644
@@ -749,9 +749,14 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
                 return -EINVAL;
             }
         } else if (!strcmp(type, "VMFS")) {
-            flat_offset = 0;
+            if (ret == 4) {
+                flat_offset = 0;
+            } else {
+                error_setg(errp, "Invalid extent lines:\n%s", p);
+                return -EINVAL;
+            }
         } else if (ret != 4) {
-            error_setg(errp, "Invalid extent lines: \n%s", p);
+            error_setg(errp, "Invalid extent lines:\n%s", p);
             return -EINVAL;
         }
 
tests/qemu-iotests/059 +14 -0
index 73941c3..65bea1d 100755
@@ -81,6 +81,20 @@ IMGOPTS="subformat=twoGbMaxExtentFlat" _make_test_img 1000G
 $QEMU_IMG info $TEST_IMG | _filter_testdir | sed -e 's/cid: [0-9]*/cid: XXXXXXXX/'
 
 echo
+echo "=== Testing malformed VMFS extent description line ==="
+cat >"$TEST_IMG" <<EOF
+# Disk DescriptorFile
+version=1
+CID=58ab4847
+parentCID=ffffffff
+createType="vmfs"
+
+# Extent description
+RW 12582912 VMFS "dummy.vmdk" 1
+EOF
+_img_info
+
+echo
 echo "=== Testing version 3 ==="
 _use_sample_img iotest-version3.vmdk.bz2
 _img_info
tests/qemu-iotests/059.out +5 -0
index 4ff935c..16ab7c6 100644
@@ -2038,6 +2038,11 @@ Format specific information:
             filename: TEST_DIR/t-f500.vmdk
             format: FLAT
 
+=== Testing malformed VMFS extent description line ===
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent lines:
+RW 12582912 VMFS "dummy.IMGFMT" 1
+
+
 === Testing version 3 ===
 image: TEST_DIR/iotest-version3.IMGFMT
 file format: IMGFMT
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 7 lines · Fam Zheng

VMFS extent line in description file should be with 4 fields:

RW <size> VMFS "file-name.vmdk"

Check the number explicitly and report error if offset is appended as FLAT, which should be invalid format.

Quoted 7 lines
---
 block/vmdk.c               |  9 +++++++--
 tests/qemu-iotests/059     | 14 ++++++++++++++
 tests/qemu-iotests/059.out |  5 +++++
 3 files changed, 26 insertions(+), 2 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan