]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage_file: Refuse qcow2 images with empty string as 'data_file'
authorPeter Krempa <pkrempa@redhat.com>
Thu, 9 Jan 2025 13:53:49 +0000 (14:53 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 20 Jan 2025 12:25:51 +0000 (13:25 +0100)
In certain buggy conditions qemu can create an image which has empty
string stored as 'data_file'. While probing libvirt would consider the
empty string as a relative file name and construct the path using the
path of the parent image stripping the last component and appending the
empty string. This results into attempting to using a directory as an
image and thus the following error when attempting to start VM with such
an image:

 error: unsupported configuration: storage type 'dir' requires use of storage format 'fat'

Reject empty strings passed in as 'data_file'.

Note that we do not have the same problem with 'backing store' as an
empty string there is interpreted as no backing file both by qemu and
libvirt.

Resolves: https://issues.redhat.com/browse/RHEL-70627
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/storage_file/storage_source.c

index 4612e710b0d0b4c8b5ff30591714af464bca3f6d..fa59949cf2937846e5c3f320065674d677d4a5ec 100644 (file)
@@ -557,6 +557,16 @@ virStorageSourceNewFromDataFile(virStorageSource *parent)
     g_autoptr(virStorageSource) dataFile = NULL;
     int rc;
 
+    /* 'qemu-img' records an empty string as 'data_file' field in certain buggy
+     * cases. Note that it can't happen for 'backing store' as absence of the
+     * string equals to no backing store. */
+    if (STREQ(parent->dataFileRaw, "")) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("invalid empty data-file definition in '%1$s'"),
+                       NULLSTR(parent->path));
+        return NULL;
+    }
+
     if ((rc = virStorageSourceNewFromChild(parent,
                                            parent->dataFileRaw,
                                            &dataFile)) < 0)