diff --git a/libexslt/functions.c b/libexslt/functions.c
index b49fbe6c..c20ca16b 100644
--- a/libexslt/functions.c
+++ b/libexslt/functions.c
@@ -331,6 +331,21 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
return;
}
+ /*
+ * When a function is called recursively during evaluation of its
+ * arguments, the recursion check in xsltApplySequenceConstructor
+ * isn't reached.
+ */
+ if (tctxt->depth >= tctxt->maxTemplateDepth) {
+ xsltTransformError(tctxt, NULL, NULL,
+ "exsltFuncFunctionFunction: Potentially infinite recursion "
+ "detected in function {%s}%s.\n",
+ ctxt->context->functionURI, ctxt->context->function);
+ tctxt->state = XSLT_STATE_STOPPED;
+ return;
+ }
+ tctxt->depth++;
+
/*
* We have a problem with the evaluation of function parameters.
* The original library code did not evaluate XPath expressions until
@@ -413,7 +428,7 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
xsltFreeStackElemList(params);
if (data->error != 0)
- return;
+ goto error;
if (data->result != NULL) {
ret = data->result;
@@ -441,10 +456,13 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
"executing a function\n",
ctxt->context->functionURI, ctxt->context->function);
xmlFreeNode(fake);
- return;
+ goto error;
}
xmlFreeNode(fake);
valuePush(ctxt, ret);
+
+error:
+ tctxt->depth--;
}
diff --git a/tests/docs/bug-201.xml b/tests/docs/bug-201.xml
new file mode 100644
index 00000000..69d62f2c
--- /dev/null
+++ b/tests/docs/bug-201.xml
@@ -0,0 +1 @@
+
diff --git a/tests/general/bug-201.err b/tests/general/bug-201.err
new file mode 100644
index 00000000..cc563c6c
--- /dev/null
+++ b/tests/general/bug-201.err
@@ -0,0 +1,6 @@
+runtime error: file ./bug-201.xsl line 13 element copy-of
+exsltFuncFunctionFunction: Potentially infinite recursion detected in function {test}func.
+xmlXPathCompiledEval: evaluation failed
+runtime error: file ./bug-201.xsl line 8 element param
+Failed to evaluate the expression of variable 'var'.
+no result for ./../docs/bug-201.xml
diff --git a/tests/general/bug-201.out b/tests/general/bug-201.out
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/general/bug-201.xsl b/tests/general/bug-201.xsl
new file mode 100644
index 00000000..fb2a6c27
--- /dev/null
+++ b/tests/general/bug-201.xsl
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+