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

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



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


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