thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-vmdk-do-not-try-opening-a-file-as-both-image-and-des.patch

9ae3a8
From 153d5ee0b61926664684a28cdfc982f956c329a2 Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <153d5ee0b61926664684a28cdfc982f956c329a2.1418766606.git.jen@redhat.com>
9ae3a8
In-Reply-To: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
9ae3a8
References: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
9ae3a8
From: Fam Zheng <famz@redhat.com>
9ae3a8
Date: Thu, 4 Dec 2014 00:05:07 -0600
9ae3a8
Subject: [CHANGE 13/31] vmdk: do not try opening a file as both image and
9ae3a8
 descriptor
9ae3a8
To: rhvirt-patches@redhat.com,
9ae3a8
    jen@redhat.com
9ae3a8
9ae3a8
RH-Author: Fam Zheng <famz@redhat.com>
9ae3a8
Message-id: <1417651524-18041-14-git-send-email-famz@redhat.com>
9ae3a8
Patchwork-id: 62686
9ae3a8
O-Subject: [RHEL-7.1 qemu-kvm PATCH v5 13/30] vmdk: do not try opening a file as both image and descriptor
9ae3a8
Bugzilla: 1134251
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
From: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
This prepares for propagating errors from vmdk_open_sparse and
9ae3a8
vmdk_open_desc_file up to the caller of vmdk_open.
9ae3a8
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Reviewed-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 37f09e5e3d206e7c555d28a7755cecfa137dad22)
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
9ae3a8
---
9ae3a8
 block/vmdk.c               | 22 +++++++++++++++-------
9ae3a8
 tests/qemu-iotests/059.out |  4 ++--
9ae3a8
 2 files changed, 17 insertions(+), 9 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/vmdk.c b/block/vmdk.c
9ae3a8
index 458bceb..94f7dae 100644
9ae3a8
--- a/block/vmdk.c
9ae3a8
+++ b/block/vmdk.c
9ae3a8
@@ -887,20 +887,28 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
     char *buf = NULL;
9ae3a8
     int ret;
9ae3a8
     BDRVVmdkState *s = bs->opaque;
9ae3a8
+    uint32_t magic;
9ae3a8
 
9ae3a8
     buf = vmdk_read_desc(bs->file, 0, errp);
9ae3a8
     if (!buf) {
9ae3a8
         return -EINVAL;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    if (vmdk_open_sparse(bs, bs->file, flags, buf, errp) == 0) {
9ae3a8
-        s->desc_offset = 0x200;
9ae3a8
-    } else {
9ae3a8
-        ret = vmdk_open_desc_file(bs, flags, buf, errp);
9ae3a8
-        if (ret) {
9ae3a8
-            goto fail;
9ae3a8
-        }
9ae3a8
+    magic = ldl_be_p(buf);
9ae3a8
+    switch (magic) {
9ae3a8
+        case VMDK3_MAGIC:
9ae3a8
+        case VMDK4_MAGIC:
9ae3a8
+            ret = vmdk_open_sparse(bs, bs->file, flags, buf, errp);
9ae3a8
+            s->desc_offset = 0x200;
9ae3a8
+            break;
9ae3a8
+        default:
9ae3a8
+            ret = vmdk_open_desc_file(bs, flags, buf, errp);
9ae3a8
+            break;
9ae3a8
     }
9ae3a8
+    if (ret) {
9ae3a8
+        goto fail;
9ae3a8
+    }
9ae3a8
+
9ae3a8
     /* try to open parent images, if exist */
9ae3a8
     ret = vmdk_parent_open(bs);
9ae3a8
     if (ret) {
9ae3a8
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
9ae3a8
index f4ca52d..0220774 100644
9ae3a8
--- a/tests/qemu-iotests/059.out
9ae3a8
+++ b/tests/qemu-iotests/059.out
9ae3a8
@@ -8,7 +8,7 @@ no file open, try 'help open'
9ae3a8
 
9ae3a8
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
9ae3a8
 L2 table size too big
9ae3a8
-qemu-io: can't open device TEST_DIR/t.vmdk: Could not open 'TEST_DIR/t.vmdk': Wrong medium type
9ae3a8
+qemu-io: can't open device TEST_DIR/t.vmdk: Could not open 'TEST_DIR/t.vmdk': Invalid argument
9ae3a8
 no file open, try 'help open'
9ae3a8
 === Testing too big L1 table size ===
9ae3a8
 
9ae3a8
@@ -2046,7 +2046,7 @@ RW 12582912 VMFS "dummy.IMGFMT" 1
9ae3a8
 === Testing truncated sparse ===
9ae3a8
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400
9ae3a8
 qemu-img: File truncated, expecting at least 13172736 bytes
9ae3a8
-qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Wrong medium type
9ae3a8
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Invalid argument
9ae3a8
 
9ae3a8
 === Testing version 3 ===
9ae3a8
 image: TEST_DIR/iotest-version3.IMGFMT
9ae3a8
-- 
9ae3a8
2.1.0
9ae3a8