]> xenbits.xensource.com Git - 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)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 4 Feb 2015 07:38:25 +0000 (08:38 +0100)
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.

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

index 8568ebb1e720a6d9fdd396d5a0faef5123596477..8d3d1f52acd3f0aa9a8ad0cecfbdba4564a6e480 100644 (file)
@@ -2156,7 +2156,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 d7597d7cddd436dce5fe474a9b6809fc601a8e18..38ce09e8c637ad1a4391f39e8d1c214f4085ad53 100644 (file)
@@ -871,6 +871,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(absqcow2, VIR_STORAGE_FILE_QCOW2,
+               (&qcow2, &nbd2), EXP_PASS,
+               (&qcow2, &nbd2), ALLOW_PROBE | EXP_PASS);
+
     /* qed file */
     testFileData qed = {
         .expBackingStoreRaw = absraw,