Blame SOURCES/libxml2-2.9.1-CVE-2016-5131.patch

83ebca
commit 3189fa5b5d1cce13e70cf282936736b2e7889a46
83ebca
Author: Nick Wellnhofer <wellnhofer@aevum.de>
83ebca
Date:   Tue Jun 28 14:22:23 2016 +0200
83ebca
83ebca
    Fix XPointer paths beginning with range-to
83ebca
    
83ebca
    The old code would invoke the totally broken xmlXPtrRangeToFunction.
83ebca
    range-to isn't really a function but a special kind of location step.
83ebca
    Remove this function and always handle range-to in the XPath code.
83ebca
    
83ebca
    The old xmlXPtrRangeToFunction could also be abused to trigger a
83ebca
    use-after-free error with the potential for remote code execution.
83ebca
83ebca
diff --git a/xpath.c b/xpath.c
83ebca
index 751665b..7c24a82 100644
83ebca
--- a/xpath.c
83ebca
+++ b/xpath.c
83ebca
@@ -10691,13 +10691,16 @@ xmlXPathCompPathExpr(xmlXPathParserContextPtr ctxt) {
83ebca
 		    lc = 1;
83ebca
 		    break;
83ebca
 		} else if ((NXT(len) == '(')) {
83ebca
-		    /* Note Type or Function */
83ebca
+		    /* Node Type or Function */
83ebca
 		    if (xmlXPathIsNodeType(name)) {
83ebca
 #ifdef DEBUG_STEP
83ebca
 		        xmlGenericError(xmlGenericErrorContext,
83ebca
 				"PathExpr: Type search\n");
83ebca
 #endif
83ebca
 			lc = 1;
83ebca
+                    } else if (ctxt->xptr &&
83ebca
+                               xmlStrEqual(name, BAD_CAST "range-to")) {
83ebca
+                        lc = 1;
83ebca
 		    } else {
83ebca
 #ifdef DEBUG_STEP
83ebca
 		        xmlGenericError(xmlGenericErrorContext,
83ebca
diff --git a/xpointer.c b/xpointer.c
83ebca
index 676c510..d74174a 100644
83ebca
--- a/xpointer.c
83ebca
+++ b/xpointer.c
83ebca
@@ -1332,8 +1332,6 @@ xmlXPtrNewContext(xmlDocPtr doc, xmlNodePtr here, xmlNodePtr origin) {
83ebca
     ret->here = here;
83ebca
     ret->origin = origin;
83ebca
 
83ebca
-    xmlXPathRegisterFunc(ret, (xmlChar *)"range-to",
83ebca
-	                 xmlXPtrRangeToFunction);
83ebca
     xmlXPathRegisterFunc(ret, (xmlChar *)"range",
83ebca
 	                 xmlXPtrRangeFunction);
83ebca
     xmlXPathRegisterFunc(ret, (xmlChar *)"range-inside",
83ebca
@@ -2243,76 +2241,14 @@ xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs) {
83ebca
  * @nargs:  the number of args
83ebca
  *
83ebca
  * Implement the range-to() XPointer function
83ebca
+ *
83ebca
+ * Obsolete. range-to is not a real function but a special type of location
83ebca
+ * step which is handled in xpath.c.
83ebca
  */
83ebca
 void
83ebca
-xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt, int nargs) {
83ebca
-    xmlXPathObjectPtr range;
83ebca
-    const xmlChar *cur;
83ebca
-    xmlXPathObjectPtr res, obj;
83ebca
-    xmlXPathObjectPtr tmp;
83ebca
-    xmlLocationSetPtr newset = NULL;
83ebca
-    xmlNodeSetPtr oldset;
83ebca
-    int i;
83ebca
-
83ebca
-    if (ctxt == NULL) return;
83ebca
-    CHECK_ARITY(1);
83ebca
-    /*
83ebca
-     * Save the expression pointer since we will have to evaluate
83ebca
-     * it multiple times. Initialize the new set.
83ebca
-     */
83ebca
-    CHECK_TYPE(XPATH_NODESET);
83ebca
-    obj = valuePop(ctxt);
83ebca
-    oldset = obj->nodesetval;
83ebca
-    ctxt->context->node = NULL;
83ebca
-
83ebca
-    cur = ctxt->cur;
83ebca
-    newset = xmlXPtrLocationSetCreate(NULL);
83ebca
-
83ebca
-    for (i = 0; i < oldset->nodeNr; i++) {
83ebca
-	ctxt->cur = cur;
83ebca
-
83ebca
-	/*
83ebca
-	 * Run the evaluation with a node list made of a single item
83ebca
-	 * in the nodeset.
83ebca
-	 */
83ebca
-	ctxt->context->node = oldset->nodeTab[i];
83ebca
-	tmp = xmlXPathNewNodeSet(ctxt->context->node);
83ebca
-	valuePush(ctxt, tmp);
83ebca
-
83ebca
-	xmlXPathEvalExpr(ctxt);
83ebca
-	CHECK_ERROR;
83ebca
-
83ebca
-	/*
83ebca
-	 * The result of the evaluation need to be tested to
83ebca
-	 * decided whether the filter succeeded or not
83ebca
-	 */
83ebca
-	res = valuePop(ctxt);
83ebca
-	range = xmlXPtrNewRangeNodeObject(oldset->nodeTab[i], res);
83ebca
-	if (range != NULL) {
83ebca
-	    xmlXPtrLocationSetAdd(newset, range);
83ebca
-	}
83ebca
-
83ebca
-	/*
83ebca
-	 * Cleanup
83ebca
-	 */
83ebca
-	if (res != NULL)
83ebca
-	    xmlXPathFreeObject(res);
83ebca
-	if (ctxt->value == tmp) {
83ebca
-	    res = valuePop(ctxt);
83ebca
-	    xmlXPathFreeObject(res);
83ebca
-	}
83ebca
-
83ebca
-	ctxt->context->node = NULL;
83ebca
-    }
83ebca
-
83ebca
-    /*
83ebca
-     * The result is used as the new evaluation set.
83ebca
-     */
83ebca
-    xmlXPathFreeObject(obj);
83ebca
-    ctxt->context->node = NULL;
83ebca
-    ctxt->context->contextSize = -1;
83ebca
-    ctxt->context->proximityPosition = -1;
83ebca
-    valuePush(ctxt, xmlXPtrWrapLocationSet(newset));
83ebca
+xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt,
83ebca
+                       int nargs ATTRIBUTE_UNUSED) {
83ebca
+    XP_ERROR(XPATH_EXPR_ERROR);
83ebca
 }
83ebca
 
83ebca
 /**