8a784f
From a436374994c47b12d5de1b8b1d191a098fa23594 Mon Sep 17 00:00:00 2001
8a784f
From: Nick Wellnhofer <wellnhofer@aevum.de>
8a784f
Date: Mon, 30 Jul 2018 12:54:38 +0200
8a784f
Subject: [PATCH] Fix nullptr deref with XPath logic ops
8a784f
8a784f
If the XPath stack is corrupted, for example by a misbehaving extension
8a784f
function, the "and" and "or" XPath operators could dereference NULL
8a784f
pointers. Check that the XPath stack isn't empty and optimize the
8a784f
logic operators slightly.
8a784f
8a784f
Closes: https://gitlab.gnome.org/GNOME/libxml2/issues/5
8a784f
8a784f
Also see
8a784f
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901817
8a784f
https://bugzilla.redhat.com/show_bug.cgi?id=1595985
8a784f
8a784f
This is CVE-2018-14404.
8a784f
8a784f
Thanks to Guy Inbar for the report.
8a784f
---
8a784f
 xpath.c | 10 ++++------
8a784f
 1 file changed, 4 insertions(+), 6 deletions(-)
8a784f
8a784f
diff --git a/xpath.c b/xpath.c
8a784f
index 3fae0bf4..5e3bb9ff 100644
8a784f
--- a/xpath.c
8a784f
+++ b/xpath.c
8a784f
@@ -13234,9 +13234,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
8a784f
 		return(0);
8a784f
 	    }
8a784f
             xmlXPathBooleanFunction(ctxt, 1);
8a784f
-            arg1 = valuePop(ctxt);
8a784f
-            arg1->boolval &= arg2->boolval;
8a784f
-            valuePush(ctxt, arg1);
8a784f
+            if (ctxt->value != NULL)
8a784f
+                ctxt->value->boolval &= arg2->boolval;
8a784f
 	    xmlXPathReleaseObject(ctxt->context, arg2);
8a784f
             return (total);
8a784f
         case XPATH_OP_OR:
8a784f
@@ -13252,9 +13251,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
8a784f
 		return(0);
8a784f
 	    }
8a784f
             xmlXPathBooleanFunction(ctxt, 1);
8a784f
-            arg1 = valuePop(ctxt);
8a784f
-            arg1->boolval |= arg2->boolval;
8a784f
-            valuePush(ctxt, arg1);
8a784f
+            if (ctxt->value != NULL)
8a784f
+                ctxt->value->boolval |= arg2->boolval;
8a784f
 	    xmlXPathReleaseObject(ctxt->context, arg2);
8a784f
             return (total);
8a784f
         case XPATH_OP_EQUAL:
8a784f
-- 
8a784f
2.22.0
8a784f