diff --git a/result/XInclude/max-recurse.xml.err b/result/XInclude/max-recurse.xml.err new file mode 100644 index 00000000..57570567 --- /dev/null +++ b/result/XInclude/max-recurse.xml.err @@ -0,0 +1,2 @@ +./test/XInclude/without-reader/max-recurse.xml:42: element include: XInclude error : maximum recursion depth exceeded +./test/XInclude/without-reader/max-recurse.xml:82: element include: XInclude error : maximum recursion depth exceeded diff --git a/test/XInclude/without-reader/max-recurse.xml b/test/XInclude/without-reader/max-recurse.xml new file mode 100644 index 00000000..cfe14bdb --- /dev/null +++ b/test/XInclude/without-reader/max-recurse.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xinclude.c b/xinclude.c index 26473863..b4585481 100644 --- a/xinclude.c +++ b/xinclude.c @@ -90,6 +90,7 @@ struct _xmlXIncludeCtxt { void *_private; /* application data */ unsigned long incTotal; /* total number of processed inclusions */ + int depth; /* recursion depth */ }; static xmlXIncludeRefPtr @@ -2036,6 +2037,12 @@ static xmlXIncludeRefPtr xmlXIncludeExpandNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node) { int nr, i; + if (ctxt->depth >= XINCLUDE_MAX_DEPTH) { + xmlXIncludeErr(ctxt, node, XML_XINCLUDE_RECURSION, + "maximum recursion depth exceeded\n", NULL); + return(NULL); + } + for (i = ctxt->incBase; i < ctxt->incNr; i++) { if (ctxt->incTab[i]->ref == node) { if (ctxt->incTab[i]->expanding) { @@ -2051,7 +2058,9 @@ xmlXIncludeExpandNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node) { return(NULL); nr = ctxt->incNr - 1; ctxt->incTab[nr]->expanding = 1; + ctxt->depth++; xmlXIncludeLoadNode(ctxt, nr); + ctxt->depth--; ctxt->incTab[nr]->expanding = 0; return(ctxt->incTab[nr]);