Commit a4363749 authored by Nick Wellnhofer's avatar Nick Wellnhofer
Browse files

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.

Closes: #5

Also see
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901817
https://bugzilla.redhat.com/show_bug.cgi?id=1595985

This is CVE-2018-14404.

Thanks to Guy Inbar for the report.
parent b7c50b8d
...@@ -13234,9 +13234,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) ...@@ -13234,9 +13234,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
return(0); return(0);
} }
xmlXPathBooleanFunction(ctxt, 1); xmlXPathBooleanFunction(ctxt, 1);
arg1 = valuePop(ctxt); if (ctxt->value != NULL)
arg1->boolval &= arg2->boolval; ctxt->value->boolval &= arg2->boolval;
valuePush(ctxt, arg1);
xmlXPathReleaseObject(ctxt->context, arg2); xmlXPathReleaseObject(ctxt->context, arg2);
return (total); return (total);
case XPATH_OP_OR: case XPATH_OP_OR:
...@@ -13252,9 +13251,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) ...@@ -13252,9 +13251,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
return(0); return(0);
} }
xmlXPathBooleanFunction(ctxt, 1); xmlXPathBooleanFunction(ctxt, 1);
arg1 = valuePop(ctxt); if (ctxt->value != NULL)
arg1->boolval |= arg2->boolval; ctxt->value->boolval |= arg2->boolval;
valuePush(ctxt, arg1);
xmlXPathReleaseObject(ctxt->context, arg2); xmlXPathReleaseObject(ctxt->context, arg2);
return (total); return (total);
case XPATH_OP_EQUAL: case XPATH_OP_EQUAL:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment