]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Sanitize parsing of disk auth XMLs
authorPeter Krempa <pkrempa@redhat.com>
Tue, 6 Mar 2018 13:17:59 +0000 (14:17 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 8 Mar 2018 13:29:49 +0000 (14:29 +0100)
Pass in the XPath context as we do in all other places rather than
allocating a new one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
src/conf/domain_conf.c
src/conf/storage_conf.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 4b722fbfbae24a05d30f8e02d13bc82879b69e11..f872ddd868dc57289273f1b2700e73f75422e2ac 100644 (file)
@@ -7218,7 +7218,8 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode,
 
 static int
 virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
-                                           virDomainHostdevSubsysSCSIPtr def)
+                                           virDomainHostdevSubsysSCSIPtr def,
+                                           xmlXPathContextPtr ctxt)
 {
     int ret = -1;
     int auth_secret_usage = -1;
@@ -7259,7 +7260,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
     while (cur != NULL) {
         if (cur->type == XML_ELEMENT_NODE &&
             virXMLNodeNameEqual(cur, "auth")) {
-            if (!(authdef = virStorageAuthDefParse(sourcenode->doc, cur)))
+            if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
                 goto cleanup;
             if ((auth_secret_usage =
                  virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
@@ -7288,7 +7289,8 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
 
 static int
 virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
-                                      virDomainHostdevSubsysSCSIPtr scsisrc)
+                                      virDomainHostdevSubsysSCSIPtr scsisrc,
+                                      xmlXPathContextPtr ctxt)
 {
     char *protocol = NULL;
     int ret = -1;
@@ -7305,7 +7307,7 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
     }
 
     if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)
-        ret = virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc);
+        ret = virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc, ctxt);
     else
         ret = virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc);
 
@@ -7550,7 +7552,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
         break;
 
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
-        if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc) < 0)
+        if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc, ctxt) < 0)
             goto error;
         break;
 
@@ -8540,7 +8542,8 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
 
 static int
 virDomainDiskSourceAuthParse(xmlNodePtr node,
-                             virStorageAuthDefPtr *authdefsrc)
+                             virStorageAuthDefPtr *authdefsrc,
+                             xmlXPathContextPtr ctxt)
 {
     xmlNodePtr child;
     virStorageAuthDefPtr authdef;
@@ -8549,7 +8552,7 @@ virDomainDiskSourceAuthParse(xmlNodePtr node,
         if (child->type == XML_ELEMENT_NODE &&
             virXMLNodeNameEqual(child, "auth")) {
 
-            if (!(authdef = virStorageAuthDefParse(node->doc, child)))
+            if (!(authdef = virStorageAuthDefParse(child, ctxt)))
                 return -1;
 
             *authdefsrc = authdef;
@@ -8653,7 +8656,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
         goto cleanup;
     }
 
-    if (virDomainDiskSourceAuthParse(node, &src->auth) < 0)
+    if (virDomainDiskSourceAuthParse(node, &src->auth, ctxt) < 0)
         goto cleanup;
 
     if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0)
@@ -9401,7 +9404,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
                 goto error;
             }
 
-            if (!(authdef = virStorageAuthDefParse(node->doc, cur)))
+            if (!(authdef = virStorageAuthDefParse(cur, ctxt)))
                 goto error;
         } else if (virXMLNodeNameEqual(cur, "iotune")) {
             if (virDomainDiskDefIotuneParse(def, ctxt) < 0)
index b9135722c189bb21cfc3deda42a8d5bc55a79a29..f1f469d462a0aa003ecc02c7a524f38ab963b1b1 100644 (file)
@@ -527,7 +527,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
     }
 
     if ((authnode = virXPathNode("./auth", ctxt))) {
-        if (!(authdef = virStorageAuthDefParse(node->doc, authnode)))
+        if (!(authdef = virStorageAuthDefParse(authnode, ctxt)))
             goto cleanup;
 
         if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
index 3d179112971dcc292ef0e36af14fe646eb35ca22..67b9ec71ac08892edfc1a54ebb9fca25f0556c37 100644 (file)
@@ -1809,16 +1809,20 @@ virStorageAuthDefCopy(const virStorageAuthDef *src)
 }
 
 
-static virStorageAuthDefPtr
-virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
+virStorageAuthDefPtr
+virStorageAuthDefParse(xmlNodePtr node,
+                       xmlXPathContextPtr ctxt)
 {
+    xmlNodePtr saveNode = ctxt->node;
     virStorageAuthDefPtr authdef = NULL;
     virStorageAuthDefPtr ret = NULL;
     xmlNodePtr secretnode = NULL;
     char *authtype = NULL;
 
+    ctxt->node = node;
+
     if (VIR_ALLOC(authdef) < 0)
-        return NULL;
+        goto cleanup;
 
     if (!(authdef->username = virXPathString("string(./@username)", ctxt))) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -1862,32 +1866,12 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
  cleanup:
     VIR_FREE(authtype);
     virStorageAuthDefFree(authdef);
+    ctxt->node = saveNode;
 
     return ret;
 }
 
 
-virStorageAuthDefPtr
-virStorageAuthDefParse(xmlDocPtr xml, xmlNodePtr root)
-{
-    xmlXPathContextPtr ctxt = NULL;
-    virStorageAuthDefPtr authdef = NULL;
-
-    ctxt = xmlXPathNewContext(xml);
-    if (ctxt == NULL) {
-        virReportOOMError();
-        goto cleanup;
-    }
-
-    ctxt->node = root;
-    authdef = virStorageAuthDefParseXML(ctxt);
-
- cleanup:
-    xmlXPathFreeContext(ctxt);
-    return authdef;
-}
-
-
 void
 virStorageAuthDefFormat(virBufferPtr buf,
                         virStorageAuthDefPtr authdef)
index 0095cd1387b0d799b888be0dec7616fa3b547c6b..596746ccb7dd94566a2b3efb75920f982206d617 100644 (file)
@@ -366,7 +366,8 @@ int virStorageFileGetSCSIKey(const char *path,
 
 void virStorageAuthDefFree(virStorageAuthDefPtr def);
 virStorageAuthDefPtr virStorageAuthDefCopy(const virStorageAuthDef *src);
-virStorageAuthDefPtr virStorageAuthDefParse(xmlDocPtr xml, xmlNodePtr root);
+virStorageAuthDefPtr virStorageAuthDefParse(xmlNodePtr node,
+                                            xmlXPathContextPtr ctxt);
 void virStorageAuthDefFormat(virBufferPtr buf, virStorageAuthDefPtr authdef);
 
 virSecurityDeviceLabelDefPtr