libxml2-2.9.8: Fix CVE-2018-14404

[No upstream tracking] -- https://gitlab.gnome.org/GNOME/libxml2/issues/5
 -- https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901817
 -- https://bugzilla.redhat.com/show_bug.cgi?id=1595985

xpath: Fix nullptr deref with XPath logic ops

If the XPath stack is corrupted, for example by a misbehaving extension
function, the "and" and "or" XPath operators could dereference NULL
pointers. Check that the XPath stack isn't empty and optimize the
logic operators slightly.

Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/libxml2/commit/a436374994c47b12d5de1b8b1d191a098fa23594]
CVE: CVE-2018-14404
Signed-off-by: Andrej Valek <andrej.valek@siemens.com>

diff --git a/xpath.c b/xpath.c
index f440696..75cac5c 100644
--- a/xpath.c
+++ b/xpath.c
@@ -13297,9 +13297,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
 		return(0);
 	    }
             xmlXPathBooleanFunction(ctxt, 1);
-            arg1 = valuePop(ctxt);
-            arg1->boolval &= arg2->boolval;
-            valuePush(ctxt, arg1);
+	    if (ctxt->value != NULL)
+		ctxt->value->boolval &= arg2->boolval;
 	    xmlXPathReleaseObject(ctxt->context, arg2);
             return (total);
         case XPATH_OP_OR:
@@ -13323,9 +13322,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
 		return(0);
 	    }
             xmlXPathBooleanFunction(ctxt, 1);
-            arg1 = valuePop(ctxt);
-            arg1->boolval |= arg2->boolval;
-            valuePush(ctxt, arg1);
+	    if (ctxt->value != NULL)
+		ctxt->value->boolval |= arg2->boolval;
 	    xmlXPathReleaseObject(ctxt->context, arg2);
             return (total);
         case XPATH_OP_EQUAL:
