1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-21 22:50:08 +03:00

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.
This commit is contained in:
Nick Wellnhofer 2017-05-25 16:57:14 +02:00
parent c851970c6e
commit aed407c14b

24
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) {