]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: storage: Fix parsing of 'exportname' from legacy NBD strings
authorPeter Krempa <pkrempa@redhat.com>
Wed, 31 Jul 2019 15:17:30 +0000 (17:17 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 16 Aug 2019 11:16:40 +0000 (13:16 +0200)
If the nbd export name contains a colon, our parser would not parse it
properly as we split the string by colons. Modify the code to look up
the exportname and copy any trailing characters as the export name is
supposed to be at the end of the string.

https://bugzilla.redhat.com/show_bug.cgi?id=1733044

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/util/virstoragefile.c
tests/virstoragetest.c

index ba56f452e90909ad8380ea90730c7071d8e4e89e..88bfa8f1600e1d01c202136d2c9365223a7f9c46 100644 (file)
@@ -2928,6 +2928,7 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
                                     virStorageSourcePtr src)
 {
     VIR_AUTOSTRINGLIST backing = NULL;
+    const char *exportname;
 
     if (!(backing = virStringSplit(nbdstr, ":", 0)))
         return -1;
@@ -2975,8 +2976,9 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
             return -1;
     }
 
-    if (backing[3] && STRPREFIX(backing[3], "exportname=")) {
-        if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=")) < 0)
+    if ((exportname = strstr(nbdstr, "exportname="))) {
+        exportname += strlen("exportname=");
+        if (VIR_STRDUP(src->path, exportname) < 0)
             return -1;
     }
 
index ef16b3c6e06beefb5d4295844d567590d6f9f08f..f558eea6225ee163b0a81fcf5472424e3cbcb47d 100644 (file)
@@ -1262,6 +1262,14 @@ mymain(void)
                        "<source protocol='nbd' name='blah'>\n"
                        "  <host name='example.org' port='6000'/>\n"
                        "</source>\n");
+    TEST_BACKING_PARSE("nbd:example.org:6000:exportname=:",
+                       "<source protocol='nbd' name=':'>\n"
+                       "  <host name='example.org' port='6000'/>\n"
+                       "</source>\n");
+    TEST_BACKING_PARSE("nbd:example.org:6000:exportname=:test",
+                       "<source protocol='nbd' name=':test'>\n"
+                       "  <host name='example.org' port='6000'/>\n"
+                       "</source>\n");
     TEST_BACKING_PARSE("nbd://example.org:1234",
                        "<source protocol='nbd'>\n"
                        "  <host name='example.org' port='1234'/>\n"