]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: storage: Fix parsing of nbd:// URI without path
authorPeter Krempa <pkrempa@redhat.com>
Tue, 3 Feb 2015 17:03:41 +0000 (18:03 +0100)
committerCole Robinson <crobinso@redhat.com>
Sun, 8 Feb 2015 02:27:03 +0000 (21:27 -0500)
If a storage file would be backed with a NBD device without path
(nbd://localhost) libvirt would crash when parsing the backing path for
the disk as the URI structure's path element is NULL in such case but
the NBD parser would access it shamelessly.

(cherry picked from commit fdb80ed4f6563928b9942a0d1450e0c725aa6c06)

src/util/virstoragefile.c
tests/virstoragetest.c

index 8e9d11560ac46e2751bb736e949bb38120512296..4a3b7ca8e1af43f12c4432c982e59ecf3b8aa4a0 100644 (file)
@@ -2166,7 +2166,8 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
     /* XXX We currently don't support auth, so don't bother parsing it */
 
     /* possibly skip the leading slash */
-    if (VIR_STRDUP(src->path,
+    if (uri->path &&
+        VIR_STRDUP(src->path,
                    *uri->path == '/' ? uri->path + 1 : uri->path) < 0)
         goto cleanup;
 
index 05e48f3a5b9fe7b050b156f9c517abea384ee04c..f350bd8475fd6d782c0a2c13d9196ef7682dd47b 100644 (file)
@@ -854,6 +854,20 @@ mymain(void)
                (&qcow2, &nbd2), EXP_PASS,
                (&qcow2, &nbd2), ALLOW_PROBE | EXP_PASS);
 
+    /* Rewrite qcow2 to use an nbd: protocol without path as backend */
+    virCommandFree(cmd);
+    cmd = virCommandNewArgList(qemuimg, "rebase", "-u", "-f", "qcow2",
+                               "-F", "raw", "-b", "nbd://example.org",
+                               "qcow2", NULL);
+    if (virCommandRun(cmd, NULL) < 0)
+        ret = -1;
+    qcow2.expBackingStoreRaw = "nbd://example.org";
+
+    nbd2.path = NULL;
+    TEST_CHAIN(20, absqcow2, VIR_STORAGE_FILE_QCOW2,
+               (&qcow2, &nbd2), EXP_PASS,
+               (&qcow2, &nbd2), ALLOW_PROBE | EXP_PASS);
+
     /* qed file */
     testFileData qed = {
         .expBackingStoreRaw = absraw,