1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Fix crash on OOM parsing storage pool XML

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>
This commit is contained in:
Daniel P. Berrange 2013-09-25 10:22:42 +01:00
parent 0dff76c2d3
commit 6b663b6fd1

View 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");