1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

snapshot: conf: Fix NULL dereference when <driver> element is empty

Consider the following valid snapshot XML as the <driver> element is
allowed to be empty in the domainsnapshot.rng schema:

$ cat snap.xml
<domainsnapshot>
  <disks>
    <disk name='vda' snapshot='external'>
      <source file='/tmp/foo'/>
      <driver/>
    </disk>
  </disks>
</domainsnapshot>

produces the following error:

$ virsh snapshot-create domain snap.xml
error: internal error: unknown disk snapshot driver '(null)'

The driver type is parsed as NULL from the XML as the attribute is not
present and then directly used to produce the error message.

With this patch the attempt to parse the driver type is skipped if not
present to avoid changing the schema to forbid the empty driver element.
This commit is contained in:
Peter Krempa 2013-11-13 11:56:47 +01:00
parent 43f2ccdc73
commit 5a66c667ff

View File

@ -154,15 +154,17 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
} else if (!def->format &&
xmlStrEqual(cur->name, BAD_CAST "driver")) {
char *driver = virXMLPropString(cur, "type");
def->format = virStorageFileFormatTypeFromString(driver);
if (def->format <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown disk snapshot driver '%s'"),
driver);
if (driver) {
def->format = virStorageFileFormatTypeFromString(driver);
if (def->format <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown disk snapshot driver '%s'"),
driver);
VIR_FREE(driver);
goto cleanup;
}
VIR_FREE(driver);
goto cleanup;
}
VIR_FREE(driver);
}
}