]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: avoid null deref during storage probe
authorEric Blake <eblake@redhat.com>
Tue, 29 Apr 2014 03:26:10 +0000 (21:26 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 29 Apr 2014 14:13:29 +0000 (08:13 -0600)
Commit 5c43e2e introduced a NULL deref if there is a failure
in virStorageFileGetMetadataInternal.

* src/util/virstoragefile.c (virStorageFileGetMetadataFromBuf):
Fix error handling.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/util/virstoragefile.c

index 1ce0fa1bc5362dba04e0d0e0fe8a1ece4123b4c6..dcce1ef13a78cafecccceba78cad0e72b719626a 100644 (file)
@@ -999,21 +999,21 @@ virStorageFileGetMetadataFromBuf(const char *path,
                                  int *backingFormat)
 {
     virStorageSourcePtr ret = NULL;
+    virStorageSourcePtr meta = NULL;
 
-    if (!(ret = virStorageFileMetadataNew(path, format)))
+    if (!(meta = virStorageFileMetadataNew(path, format)))
         return NULL;
 
-    if (virStorageFileGetMetadataInternal(ret, buf, len,
-                                          backingFormat) < 0) {
-        virStorageSourceFree(ret);
-        ret = NULL;
-    }
-
-    if (VIR_STRDUP(*backing, ret->backingStoreRaw) < 0) {
-        virStorageSourceFree(ret);
-        ret = NULL;
-    }
+    if (virStorageFileGetMetadataInternal(meta, buf, len,
+                                          backingFormat) < 0)
+        goto cleanup;
+    if (VIR_STRDUP(*backing, meta->backingStoreRaw) < 0)
+        goto cleanup;
 
+    ret = meta;
+    meta = NULL;
+ cleanup:
+    virStorageSourceFree(meta);
     return ret;
 }