diff mbox series

[PULL,4/4] block/vpc: Add a sanity check that fixed-size images have the right type

Message ID 20211102142219.697650-5-hreitz@redhat.com
State New
Headers show
Series [PULL,1/4] qemu-img: Consistent docs for convert -F | expand

Commit Message

Hanna Czenczek Nov. 2, 2021, 2:22 p.m. UTC
From: Thomas Huth <thuth@redhat.com>

The code in vpc.c uses BDRVVPCState->footer.type in various places
to decide whether the image is a fixed-size (VHD_FIXED) or a dynamic
(VHD_DYNAMIC) image. However, we never check that this field really
contains VHD_FIXED if we detected a fixed size image in vpc_open(),
so a wrong value here could cause quite some trouble during runtime.

Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20211012082702.792259-1-thuth@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
 block/vpc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/block/vpc.c b/block/vpc.c
index 1b4c7333af..297a26262a 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -276,7 +276,8 @@  static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
         if (ret < 0) {
             goto fail;
         }
-        if (strncmp(footer->creator, "conectix", 8)) {
+        if (strncmp(footer->creator, "conectix", 8) ||
+            be32_to_cpu(footer->type) != VHD_FIXED) {
             error_setg(errp, "invalid VPC image");
             ret = -EINVAL;
             goto fail;