From 3837f285157d333f06a98cb2f9026d07d19174bc Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 16 Sep 2022 18:23:29 +0200 Subject: [PATCH] virDomainNetDefParseXML: Parse attributes of only when present MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Access the 'mac_node' variable only when it was filled. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/domain_conf.c | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4b0a76e360..a95fb0eadb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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) { -- 2.47.2