From: Tim Wiederhake Date: Tue, 20 Apr 2021 11:27:49 +0000 (+0200) Subject: virxml: Fix schema validation of individual nodes X-Git-Tag: v7.3.0-rc1~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=baaf79ac0e7469a44ab4de8a052b19c0bfeef59f;p=thirdparty%2Flibvirt.git virxml: Fix schema validation of individual nodes xmlDocSetRootElement removes the node from its previous document tree, effectively removing the "" node from "" in virCPUDefParseXML. Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index c7bea8ae00..58ca1e2019 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -355,8 +355,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, PKGDATADIR "/schemas"))) return -1; - if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->doc, - ctxt->node) < 0) + if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->node) < 0) return -1; } diff --git a/src/util/virxml.c b/src/util/virxml.c index d0d9494009..418be2a898 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1551,16 +1551,15 @@ virXMLValidateAgainstSchema(const char *schemafile, int -virXMLValidateNodeAgainstSchema(const char *schemafile, - xmlDocPtr doc, - xmlNodePtr node) +virXMLValidateNodeAgainstSchema(const char *schemafile, xmlNodePtr node) { - xmlNodePtr root; int ret; + xmlDocPtr copy = xmlNewDoc(NULL); - root = xmlDocSetRootElement(doc, node); - ret = virXMLValidateAgainstSchema(schemafile, doc); - xmlDocSetRootElement(doc, root); + xmlDocSetRootElement(copy, xmlCopyNode(node, true)); + ret = virXMLValidateAgainstSchema(schemafile, copy); + + xmlFreeDoc(copy); return ret; } diff --git a/src/util/virxml.h b/src/util/virxml.h index 2b40398eee..c0405a39f0 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -296,7 +296,6 @@ virXMLValidateAgainstSchema(const char *schemafile, int virXMLValidateNodeAgainstSchema(const char *schemafile, - xmlDocPtr doc, xmlNodePtr node); void