Skip to content

Commit 7c4fef2

Browse files
committed
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.
1 parent d4e4f6f commit 7c4fef2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

xpath.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13030,6 +13030,7 @@ xmlXPathOptimizeExpression(xmlXPathParserContextPtr pctxt,
1303013030
xmlXPathCompExprPtr
1303113031
xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
1303213032
xmlXPathParserContextPtr pctxt;
13033+
xmlXPathContextPtr tmpctxt = NULL;
1303313034
xmlXPathCompExprPtr comp;
1303413035
int oldDepth = 0;
1303513036

@@ -13041,18 +13042,32 @@ xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
1304113042

1304213043
xmlInitParser();
1304313044

13045+
/*
13046+
* We need an xmlXPathContext for the depth check.
13047+
*/
13048+
if (ctxt == NULL) {
13049+
tmpctxt = xmlXPathNewContext(NULL);
13050+
if (tmpctxt == NULL)
13051+
return(NULL);
13052+
ctxt = tmpctxt;
13053+
}
13054+
1304413055
pctxt = xmlXPathNewParserContext(str, ctxt);
13045-
if (pctxt == NULL)
13056+
if (pctxt == NULL) {
13057+
if (tmpctxt != NULL)
13058+
xmlXPathFreeContext(tmpctxt);
1304613059
return NULL;
13047-
if (ctxt != NULL)
13048-
oldDepth = ctxt->depth;
13060+
}
13061+
13062+
oldDepth = ctxt->depth;
1304913063
xmlXPathCompileExpr(pctxt, 1);
13050-
if (ctxt != NULL)
13051-
ctxt->depth = oldDepth;
13064+
ctxt->depth = oldDepth;
1305213065

1305313066
if( pctxt->error != XPATH_EXPRESSION_OK )
1305413067
{
1305513068
xmlXPathFreeParserContext(pctxt);
13069+
if (tmpctxt != NULL)
13070+
xmlXPathFreeContext(tmpctxt);
1305613071
return(NULL);
1305713072
}
1305813073

@@ -13077,6 +13092,8 @@ xmlXPathCtxtCompile(xmlXPathContextPtr ctxt, const xmlChar *str) {
1307713092
pctxt->comp = NULL;
1307813093
}
1307913094
xmlXPathFreeParserContext(pctxt);
13095+
if (tmpctxt != NULL)
13096+
xmlXPathFreeContext(tmpctxt);
1308013097

1308113098
if (comp != NULL) {
1308213099
comp->expr = xmlStrdup(str);

0 commit comments

Comments
 (0)