From 0b69d47774c9cb42c4f9d637dd0760b02649cfdb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Tomko?= Date: Thu, 20 Feb 2025 22:48:40 +0100 Subject: [PATCH] conf: metadata: ignore empty metadata element MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Do not copy the node to domain/network definition if its empty. Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 4 +++- src/conf/network_conf.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 206b0480ca..d2d35abb7b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19855,8 +19855,10 @@ virDomainDefParseXML(xmlXPathContextPtr ctxt, return NULL; /* Extract custom metadata */ - if ((node = virXPathNode("./metadata[1]", ctxt)) != NULL) + if ((node = virXPathNode("./metadata[1]", ctxt)) != NULL && + xmlFirstElementChild(node)) { def->metadata = xmlCopyNode(node, 1); + } /* we have to make a copy of all of the callback pointers here since * we won't have the virCaps structure available during free diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 316a84502d..8cd26de72f 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1898,7 +1898,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, } /* Extract custom metadata */ - if ((metadataNode = virXPathNode("./metadata[1]", ctxt)) != NULL) { + if ((metadataNode = virXPathNode("./metadata[1]", ctxt)) != NULL && + xmlFirstElementChild(metadataNode)) { def->metadata = xmlCopyNode(metadataNode, 1); virXMLNodeSanitizeNamespaces(def->metadata); } -- 2.47.3