From 88927f4922aae25dda3a5cf42afada3edd8da0fc Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 31 Oct 2014 15:57:45 +0000
Subject: [PATCH] v2v: Add bounds check to Xml.xpathobj_node function.
I accidentally called it with an out-of-bounds index, and it caused a
core dump. Add a bounds check to stop this from happening in
production.
(cherry picked from commit 1470be7f3b36b9ba6862fd04aa66446e89b108a7)
---
v2v/xml-c.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/v2v/xml-c.c b/v2v/xml-c.c
index f26e362..0b619e5 100644
--- a/v2v/xml-c.c
+++ b/v2v/xml-c.c
@@ -197,6 +197,9 @@ v2v_xml_xpathobj_get_node_ptr (value xpathobjv, value iv)
xmlXPathObjectPtr xpathobj = Xpathobj_val (xpathobjv);
int i = Int_val (iv);
+ if (i < 0 || i >= xpathobj->nodesetval->nodeNr)
+ caml_invalid_argument ("get_node_ptr: node number out of range");
+
/* Because xmlNodePtrs are owned by the document, we don't want to
* wrap this up with a finalizer, so just pass the pointer straight
* back to OCaml as a value. OCaml will ignore it because it's
--
1.8.3.1