1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

xpath: Make recursion check work with xmlXPathCompile

The check for maximum recursion depth required a parser context with an
xmlXPathContext which xmlXPathCompile didn't provide.

All other code should already set up or require an xmlXPathContext.
This commit is contained in:
Nick Wellnhofer 2024-09-13 20:59:47 +02:00
parent dae160c64b
commit 03f1bdd260

27
xpath.c
View File

@ -12353,6 +12353,7 @@ xmlXPathOptimizeExpression(xmlXPathParserContextPtr pctxt,
xmlXPathCompExprPtr
xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
xmlXPathParserContextPtr pctxt;
xmlXPathContextPtr tmpctxt = NULL;
xmlXPathCompExprPtr comp;
int oldDepth = 0;
@ -12364,18 +12365,32 @@ xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
xmlInitParser();
/*
* We need an xmlXPathContext for the depth check.
*/
if (ctxt == NULL) {
tmpctxt = xmlXPathNewContext(NULL);
if (tmpctxt == NULL)
return(NULL);
ctxt = tmpctxt;
}
pctxt = xmlXPathNewParserContext(str, ctxt);
if (pctxt == NULL)
if (pctxt == NULL) {
if (tmpctxt != NULL)
xmlXPathFreeContext(tmpctxt);
return NULL;
if (ctxt != NULL)
oldDepth = ctxt->depth;
}
oldDepth = ctxt->depth;
xmlXPathCompileExpr(pctxt, 1);
if (ctxt != NULL)
ctxt->depth = oldDepth;
ctxt->depth = oldDepth;
if( pctxt->error != XPATH_EXPRESSION_OK )
{
xmlXPathFreeParserContext(pctxt);
if (tmpctxt != NULL)
xmlXPathFreeContext(tmpctxt);
return(NULL);
}
@ -12400,6 +12415,8 @@ xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
pctxt->comp = NULL;
}
xmlXPathFreeParserContext(pctxt);
if (tmpctxt != NULL)
xmlXPathFreeContext(tmpctxt);
if (comp != NULL) {
comp->expr = xmlStrdup(str);