]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix crash on OOM parsing storage pool XML
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 25 Sep 2013 09:22:42 +0000 (10:22 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 25 Sep 2013 17:12:08 +0000 (18:12 +0100)
The virStoragePoolDefParseSource method would set def->nhosts
before allocating def->hosts. If the allocation failed due to
OOM, the cleanup code would crash accessing out of bounds.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/conf/storage_conf.c

index 002663f1e4e3f92aecbec8b5099e2d8ec81dc4d8..975e66264135612d61bc04e538abe6388c3688e1 100644 (file)
@@ -594,11 +594,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
 
     if ((n = virXPathNodeSet("./host", ctxt, &nodeset)) < 0)
         goto cleanup;
-    source->nhost = n;
 
-    if (source->nhost) {
-        if (VIR_ALLOC_N(source->hosts, source->nhost) < 0)
+    if (n) {
+        if (VIR_ALLOC_N(source->hosts, n) < 0)
             goto cleanup;
+        source->nhost = n;
 
         for (i = 0; i < source->nhost; i++) {
             name = virXMLPropString(nodeset[i], "name");