1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

xinclude: Limit recursion depth

This avoids call stack overflows.
This commit is contained in:
Nick Wellnhofer
2022-10-22 16:50:18 +02:00
parent 34496f26db
commit d2ed1e4f99
3 changed files with 115 additions and 0 deletions

View File

@@ -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]);