|
| 1 | +From a436374994c47b12d5de1b8b1d191a098fa23594 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Nick Wellnhofer <wellnhofer@aevum.de> |
| 3 | +Date: Mon, 30 Jul 2018 12:54:38 +0200 |
| 4 | +Subject: [PATCH] Fix nullptr deref with XPath logic ops |
| 5 | + |
| 6 | +If the XPath stack is corrupted, for example by a misbehaving extension |
| 7 | +function, the "and" and "or" XPath operators could dereference NULL |
| 8 | +pointers. Check that the XPath stack isn't empty and optimize the |
| 9 | +logic operators slightly. |
| 10 | + |
| 11 | +Closes: https://gitlab.gnome.org/GNOME/libxml2/issues/5 |
| 12 | + |
| 13 | +Also see |
| 14 | +https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901817 |
| 15 | +https://bugzilla.redhat.com/show_bug.cgi?id=1595985 |
| 16 | + |
| 17 | +This is CVE-2018-14404. |
| 18 | + |
| 19 | +Thanks to Guy Inbar for the report. |
| 20 | +--- |
| 21 | + xpath.c | 10 ++++------ |
| 22 | + 1 file changed, 4 insertions(+), 6 deletions(-) |
| 23 | + |
| 24 | +diff --git a/xpath.c b/xpath.c |
| 25 | +index 3fae0bf..5e3bb9f 100644 |
| 26 | +--- a/xpath.c |
| 27 | ++++ b/xpath.c |
| 28 | +@@ -13234,9 +13234,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) |
| 29 | + return(0); |
| 30 | + } |
| 31 | + xmlXPathBooleanFunction(ctxt, 1); |
| 32 | +- arg1 = valuePop(ctxt); |
| 33 | +- arg1->boolval &= arg2->boolval; |
| 34 | +- valuePush(ctxt, arg1); |
| 35 | ++ if (ctxt->value != NULL) |
| 36 | ++ ctxt->value->boolval &= arg2->boolval; |
| 37 | + xmlXPathReleaseObject(ctxt->context, arg2); |
| 38 | + return (total); |
| 39 | + case XPATH_OP_OR: |
| 40 | +@@ -13252,9 +13251,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) |
| 41 | + return(0); |
| 42 | + } |
| 43 | + xmlXPathBooleanFunction(ctxt, 1); |
| 44 | +- arg1 = valuePop(ctxt); |
| 45 | +- arg1->boolval |= arg2->boolval; |
| 46 | +- valuePush(ctxt, arg1); |
| 47 | ++ if (ctxt->value != NULL) |
| 48 | ++ ctxt->value->boolval |= arg2->boolval; |
| 49 | + xmlXPathReleaseObject(ctxt->context, arg2); |
| 50 | + return (total); |
| 51 | + case XPATH_OP_EQUAL: |
| 52 | +-- |
| 53 | +2.17.1 |
| 54 | + |
0 commit comments