From: Eric Blake Date: Tue, 29 Apr 2014 03:26:10 +0000 (-0600) Subject: conf: avoid null deref during storage probe X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=c9679edca9cc876d63f12c80d21f57aceacc97bd;p=libvirt.git conf: avoid null deref during storage probe 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 --- diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 1ce0fa1bc5..dcce1ef13a 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -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; }