mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2025-08-07 10:42:55 +03:00
Backup context node in exsltFuncFunctionFunction
exsltFuncFunctionFunction handles XPath extension functions and is called from the XPath engine. Since evaluation of function templates can change the XPath context node, it must be backed up to avoid corruption. Without proper backup, evaluating certain content in function templates could also result in use-after-free errors. It seems that libxml2 commit 029d0e96 helped to expose the error. Fixes #11.
This commit is contained in:
@@ -291,7 +291,7 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
|
||||
xmlXPathObjectPtr oldResult, ret;
|
||||
exsltFuncData *data;
|
||||
exsltFuncFunctionData *func;
|
||||
xmlNodePtr paramNode, oldInsert, fake;
|
||||
xmlNodePtr paramNode, oldInsert, oldXPNode, fake;
|
||||
int oldBase;
|
||||
void *oldCtxtVar;
|
||||
xsltStackElemPtr params = NULL, param;
|
||||
@@ -360,6 +360,9 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
|
||||
}
|
||||
tctxt->depth++;
|
||||
|
||||
/* Evaluating templates can change the XPath context node. */
|
||||
oldXPNode = tctxt->xpathCtxt->node;
|
||||
|
||||
/*
|
||||
* We have a problem with the evaluation of function parameters.
|
||||
* The original library code did not evaluate XPath expressions until
|
||||
@@ -446,6 +449,7 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
|
||||
data->ctxtVar = oldCtxtVar;
|
||||
if (params != NULL)
|
||||
xsltFreeStackElemList(params);
|
||||
tctxt->xpathCtxt->node = oldXPNode;
|
||||
|
||||
if (data->error != 0)
|
||||
goto error;
|
||||
|
Reference in New Issue
Block a user