]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virxml: Fix schema validation of individual nodes
authorTim Wiederhake <twiederh@redhat.com>
Tue, 20 Apr 2021 11:27:49 +0000 (13:27 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 21 Apr 2021 08:20:41 +0000 (10:20 +0200)
xmlDocSetRootElement removes the node from its previous document tree,
effectively removing the "<cpu>" node from "<domain>" in virCPUDefParseXML.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/cpu_conf.c
src/util/virxml.c
src/util/virxml.h

index c7bea8ae00b17b43a3122fd01d2711a7264c5551..58ca1e20190f7f9fd905006f29727b8d2e8dd08e 100644 (file)
@@ -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;
     }
 
index d0d9494009955b670a13100c18ab63286486ac94..418be2a89822c1ed39aa6b943c0a5f582c25d401 100644 (file)
@@ -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;
 }
 
index 2b40398eee14fe4cc6ecaf50e43eadfdfff5cfd9..c0405a39f0bb84928e3bd5e76736a67d9bcc1305 100644 (file)
@@ -296,7 +296,6 @@ virXMLValidateAgainstSchema(const char *schemafile,
 
 int
 virXMLValidateNodeAgainstSchema(const char *schemafile,
-                                xmlDocPtr doc,
                                 xmlNodePtr node);
 
 void