1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-26 03:21:44 +03:00

virDomainNetDefParseXML: Parse attributes of <mac> only when present

Access the 'mac_node' variable only when it was filled.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-09-16 18:23:29 +02:00
parent 3d81ed1448
commit 3837f28515

View File

@ -9321,37 +9321,37 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
if ((tap = virXPathString("string(./backend/@tap)", ctxt)))
def->backend.tap = virFileSanitizePath(tap);
mac_node = virXPathNode("./mac", ctxt);
if ((mac_node = virXPathNode("./mac", ctxt))) {
if ((macaddr = virXMLPropString(mac_node, "address"))) {
if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unable to parse mac address '%s'"),
(const char *)macaddr);
return NULL;
}
if (virMacAddrIsMulticast(&def->mac)) {
virReportError(VIR_ERR_XML_ERROR,
_("expected unicast mac address, found multicast '%s'"),
(const char *)macaddr);
return NULL;
}
}
if ((macaddr = virXMLPropString(mac_node, "address"))) {
if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unable to parse mac address '%s'"),
(const char *)macaddr);
if (virXMLPropEnum(mac_node, "type",
virDomainNetMacTypeTypeFromString,
VIR_XML_PROP_NONZERO, &def->mac_type) < 0)
return NULL;
}
if (virMacAddrIsMulticast(&def->mac)) {
virReportError(VIR_ERR_XML_ERROR,
_("expected unicast mac address, found multicast '%s'"),
(const char *)macaddr);
if (virXMLPropTristateBool(mac_node, "check", VIR_XML_PROP_NONE,
&def->mac_check) < 0)
return NULL;
}
} else {
}
if (!macaddr) {
virDomainNetGenerateMAC(xmlopt, &def->mac);
def->mac_generated = true;
}
if (virXMLPropEnum(mac_node, "type",
virDomainNetMacTypeTypeFromString,
VIR_XML_PROP_NONZERO,
&def->mac_type) < 0)
return NULL;
if (virXMLPropTristateBool(mac_node, "check",
VIR_XML_PROP_NONE,
&def->mac_check) < 0)
return NULL;
if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info,
flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT
| VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) < 0) {