[Libguestfs] [PATCH 08/14] v2v: Avoid segfault if xpath expression doesn't match any nodes.

Richard W.M. Jones rjones at redhat.com
Mon Jun 23 11:32:24 UTC 2014


I'm not sure if this indicates that the xpath expression is wrong, but
in any case it can be that xpathobj->nodesetval is NULL.  In this
case, return 0 from xpathobj_nr_nodes instead of segfaulting.
---
 v2v/xml-c.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/v2v/xml-c.c b/v2v/xml-c.c
index a1b796c..cf5bff2 100644
--- a/v2v/xml-c.c
+++ b/v2v/xml-c.c
@@ -165,7 +165,10 @@ v2v_xml_xpathobj_nr_nodes (value xpathobjv)
   CAMLparam1 (xpathobjv);
   xmlXPathObjectPtr xpathobj = Xpathobj_val (xpathobjv);
 
-  CAMLreturn (Val_int (xpathobj->nodesetval->nodeNr));
+  if (xpathobj->nodesetval == NULL)
+    CAMLreturn (Val_int (0));
+  else
+    CAMLreturn (Val_int (xpathobj->nodesetval->nodeNr));
 }
 
 value
-- 
1.9.0




More information about the Libguestfs mailing list