]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: do not steal pointers from the pool source
authorJán Tomko <jtomko@redhat.com>
Tue, 28 Mar 2017 13:11:52 +0000 (15:11 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 29 Mar 2017 08:36:55 +0000 (10:36 +0200)
Since commit fcbbb28 we steal the pointer to the storage pool
source name if there was no pool name specified.

Properly duplicate the string to avoid freeing it twice.

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

src/conf/storage_conf.c
tests/storagepoolxml2xmlout/pool-logical-noname.xml [new file with mode: 0644]
tests/storagepoolxml2xmltest.c

index 585ca71aaf6837dc8845358eee9cb88d3c6626e0..fe0f0bcdc7f7dd6f3ea4d65011225843733bb5a9 100644 (file)
@@ -710,8 +710,9 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
 
     ret->name = virXPathString("string(./name)", ctxt);
     if (ret->name == NULL &&
-        options->flags & VIR_STORAGE_POOL_SOURCE_NAME)
-        ret->name = ret->source.name;
+        options->flags & VIR_STORAGE_POOL_SOURCE_NAME &&
+        VIR_STRDUP(ret->name, ret->source.name) < 0)
+        goto error;
     if (ret->name == NULL) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("missing pool source name element"));
diff --git a/tests/storagepoolxml2xmlout/pool-logical-noname.xml b/tests/storagepoolxml2xmlout/pool-logical-noname.xml
new file mode 100644 (file)
index 0000000..a5e0ead
--- /dev/null
@@ -0,0 +1,19 @@
+<pool type='logical'>
+  <name>zily</name>
+  <uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid>
+  <capacity unit='bytes'>0</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <available unit='bytes'>0</available>
+  <source>
+    <name>zily</name>
+    <format type='lvm2'/>
+  </source>
+  <target>
+    <path>/dev/zily</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
index 79bdc26da521fd367ad2e442a9667d861199f670..355871c618d52a8178e2b19b619d028d14821b5b 100644 (file)
@@ -79,6 +79,7 @@ mymain(void)
     DO_TEST("pool-logical");
     DO_TEST("pool-logical-nopath");
     DO_TEST("pool-logical-create");
+    DO_TEST("pool-logical-noname");
     DO_TEST("pool-disk");
     DO_TEST("pool-disk-device-nopartsep");
     DO_TEST("pool-iscsi");