Skip to content

Commit fe9da13

Browse files
committed
transform: Check maximum depth when processing default templates
Avoids a call stack overflow. Found by OSS-Fuzz.
1 parent 97bbff0 commit fe9da13

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

libxslt/transform.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,21 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node,
19921992
case XML_ELEMENT_NODE:
19931993
ctxt->xpathCtxt->contextSize = nbchild;
19941994
ctxt->xpathCtxt->proximityPosition = childno;
1995+
1996+
if (ctxt->depth >= ctxt->maxTemplateDepth) {
1997+
xsltTransformError(ctxt, NULL, cur,
1998+
"xsltDefaultProcessOneNode: Maximum template depth "
1999+
"exceeded.\n"
2000+
"You can adjust xsltMaxDepth (--maxdepth) in order to "
2001+
"raise the maximum number of nested template calls and "
2002+
"variables/params (currently set to %d).\n",
2003+
ctxt->maxTemplateDepth);
2004+
ctxt->state = XSLT_STATE_STOPPED;
2005+
return;
2006+
}
2007+
ctxt->depth++;
19952008
xsltProcessOneNode(ctxt, cur, params);
2009+
ctxt->depth--;
19962010
break;
19972011
case XML_CDATA_SECTION_NODE:
19982012
template = xsltGetTemplate(ctxt, cur, NULL);

0 commit comments

Comments
 (0)