[libxml2] Check for trailing characters in XPath expressions earlier



commit aed407c14bb67368f7ff1d691ee566e276ba9a32
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Thu May 25 16:57:14 2017 +0200

    Check for trailing characters in XPath expressions earlier
    
    Move the check for trailing characters from xmlXPathEval to
    xmlXPathEvalExpr. Otherwise, a valid portion of a syntactically invalid
    expression would be evaluated before returning an error.

 xpath.c |   24 ++++++++----------------
 1 files changed, 8 insertions(+), 16 deletions(-)
---
diff --git a/xpath.c b/xpath.c
index d5ce3e3..ff44799 100644
--- a/xpath.c
+++ b/xpath.c
@@ -15052,22 +15052,21 @@ xmlXPathEvalExpr(xmlXPathParserContextPtr ctxt) {
         if (ctxt->comp != NULL)
            xmlXPathFreeCompExpr(ctxt->comp);
         ctxt->comp = comp;
-       if (ctxt->cur != NULL)
-           while (*ctxt->cur != 0) ctxt->cur++;
     } else
 #endif
     {
        xmlXPathCompileExpr(ctxt, 1);
-       if ((ctxt->error == XPATH_EXPRESSION_OK) &&
-           (ctxt->comp != NULL) &&
-           (ctxt->comp->nbStep > 1) &&
-           (ctxt->comp->last >= 0))
-       {
+        CHECK_ERROR;
+
+        /* Check for trailing characters. */
+        if (*ctxt->cur != 0)
+            XP_ERROR(XPATH_EXPR_ERROR);
+
+       if ((ctxt->comp->nbStep > 1) && (ctxt->comp->last >= 0))
            xmlXPathOptimizeExpression(ctxt->comp,
                &ctxt->comp->steps[ctxt->comp->last]);
-       }
     }
-    CHECK_ERROR;
+
     xmlXPathRunEval(ctxt, 0);
 }
 
@@ -15097,13 +15096,6 @@ xmlXPathEval(const xmlChar *str, xmlXPathContextPtr ctx) {
 
     if (ctxt->error != XPATH_EXPRESSION_OK) {
        res = NULL;
-    } else if ((*ctxt->cur != 0) && (ctxt->comp != NULL)
-#ifdef XPATH_STREAMING
-            && (ctxt->comp->stream == NULL)
-#endif
-             ) {
-       xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_EXPR_ERROR);
-       res = NULL;
     } else {
        res = valuePop(ctxt);
         if (res == NULL) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]