[libvirt] [PATCH] consolidate virXPathNodeSet()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  While reviewing Rich last patch I was afraid that virXPathNodeSet()
could return -1 when doing an evaluation failure. It is based on
xmlXPathEval() from libxml2 whose behaviour is to possibly return NULL
on XPath evaluation failure independantly of the kind of failure:

    http://xmlsoft.org/html/libxml-xpath.html#xmlXPathEval

  I suggest to apply this patch to make sure we always return 0
unless the returned XPath type is of the wrong type (meaning the
query passed didn't evaluate to a node set and code must be fixed)

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
diff --git a/src/util/xml.c b/src/util/xml.c
index 4118d2a..4fa443d 100644
--- a/src/util/xml.c
+++ b/src/util/xml.c
@@ -490,11 +490,16 @@ virXPathNodeSet(virConnectPtr conn,
     relnode = ctxt->node;
     obj = xmlXPathEval(BAD_CAST xpath, ctxt);
     ctxt->node = relnode;
-    if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
-        (obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 0)) {
+    if (obj == NULL)
+        return(0);
+    if (obj->type != XPATH_NODESET) {
         xmlXPathFreeObject(obj);
         return (-1);
     }
+    if ((obj->nodesetval == NULL)  || (obj->nodesetval->nodeNr < 0)) {
+        xmlXPathFreeObject(obj);
+        return (0);
+    }
 
     ret = obj->nodesetval->nodeNr;
     if (list != NULL && ret) {
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]