From fad19c9b8abb2a310ecfc5c3acacc125712f5d38 Mon Sep 17 00:00:00 2001 From: "William M. Brack" Date: Sun, 23 Nov 2003 23:37:19 +0000 Subject: [PATCH] Changed to detect recursion in xslt:import (bug #127687). regenerated to * libxslt/xslt.c, libxslt/imports.c, libxslt/parserInternals.h: Changed to detect recursion in xslt:import (bug #127687). * doc/libxslt-api.xml, python/libxsltclass.txt: regenerated to include change to xsltParseStylesheetImportedDoc parameters for above. --- ChangeLog | 8 + doc/libxslt-api.xml | 794 ++++++++++++++++++---------------------- libxslt/imports.c | 15 +- libxslt/xslt.c | 8 +- libxslt/xsltInternals.h | 3 +- python/libxsltclass.txt | 6 +- 6 files changed, 388 insertions(+), 446 deletions(-) diff --git a/ChangeLog b/ChangeLog index dee1d8b1..447acec9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Nov 24 07:32:38 HKT 2003 William Brack + + * libxslt/xslt.c, libxslt/imports.c, libxslt/parserInternals.h: + Changed to detect recursion in xslt:import (bug #127687). + * doc/libxslt-api.xml, python/libxsltclass.txt: regenerated to + include change to xsltParseStylesheetImportedDoc parameters for + above. + Sat Nov 22 13:04:59 CET 2003 Daniel Veillard * libxslt/keys.c libxslt/templates.c libxslt/transform.c diff --git a/doc/libxslt-api.xml b/doc/libxslt-api.xml index 2aa1e0eb..aa2476e5 100644 --- a/doc/libxslt-api.xml +++ b/doc/libxslt-api.xml @@ -1,388 +1,375 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -530,8 +517,6 @@ - - @@ -835,14 +820,6 @@ informations are stored'/> - - Register the XSLT pattern associated to @cur - - - - - - Allocate an extra runtime information slot statically while compiling the stylesheet and return its number @@ -989,11 +966,6 @@ informations are stored'/> Unregister all global variables set up by the XSLT library - - Cleanup the state of the templates used by the stylesheet and the ones it imports. - - - Process the xslt comment node on the source node @@ -1002,15 +974,6 @@ informations are stored'/> - - Compile the XSLT pattern and generates a list of precompiled form suitable for fast matching. [1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern - - - - - - - reorder the current node list accordingly to the set of sorting requirement provided by the array of nodes. @@ -1303,11 +1266,6 @@ informations are stored'/> - - Free up the memory allocated by all the elements of @comp - - - Free the XSLT extension data @@ -1373,11 +1331,6 @@ informations are stored'/> - - Free up the memory used by xsltAddTemplate/xsltGetTemplate mechanism - - - Free up the memory allocated by @ctxt @@ -1470,13 +1423,6 @@ informations are stored'/> - - Finds the template applying to this node, if @style is non-NULL it means one needs to look for the next imported template in scope. - - - - - Read one UTF8 Char from @utf Function copied from libxml2 xmlGetUTF8Char() ... to discard ultimately and use the original API @@ -1551,15 +1497,6 @@ informations are stored'/> - - - - - - - - - Process and xsl:message construct @@ -1616,13 +1553,6 @@ informations are stored'/> - - This is a hashtable scanner function to normalize the compiled steps of an imported stylesheet. - - - - - Process the xslt number node on the source node @@ -1681,7 +1611,8 @@ informations are stored'/> parse an XSLT stylesheet building the associated structures except the processing not needed for imported documents. - + + parse an XSLT stylesheet include element @@ -2081,13 +2012,6 @@ informations are stored'/> - - Test wether the node matches one of the patterns in the list - - - - - Process the xslt text node on the source node diff --git a/libxslt/imports.c b/libxslt/imports.c index eea90c19..e624d9e4 100644 --- a/libxslt/imports.c +++ b/libxslt/imports.c @@ -91,6 +91,18 @@ xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) { goto error; } + res = style; + while (res != NULL) { + if (res->doc == NULL) + break; + if (xmlStrEqual(res->doc->URL, URI)) { + xsltTransformError(NULL, style, cur, + "xsl:import : recursion detected on imported URL %s\n", URI); + goto error; + } + res = res->parent; + } + /* * Security framework check */ @@ -118,9 +130,8 @@ xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) { goto error; } - res = xsltParseStylesheetImportedDoc(import); + res = xsltParseStylesheetImportedDoc(import, style); if (res != NULL) { - res->parent = style; res->next = style->imports; style->imports = res; xmlHashScan(res->templatesHash, diff --git a/libxslt/xslt.c b/libxslt/xslt.c index b505f660..e65793b6 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -1966,7 +1966,8 @@ xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc) { /** * xsltParseStylesheetImportedDoc: - * @doc: and xmlDoc parsed XML + * @doc: an xmlDoc parsed XML + * @style: pointer to parent stylesheet * * parse an XSLT stylesheet building the associated structures * except the processing not needed for imported documents. @@ -1975,7 +1976,7 @@ xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc) { */ xsltStylesheetPtr -xsltParseStylesheetImportedDoc(xmlDocPtr doc) { +xsltParseStylesheetImportedDoc(xmlDocPtr doc, xsltStylesheetPtr style) { xsltStylesheetPtr ret; if (doc == NULL) @@ -1986,6 +1987,7 @@ xsltParseStylesheetImportedDoc(xmlDocPtr doc) { return(NULL); ret->doc = doc; + ret->parent = style; /* needed to prevent loops */ xsltGatherNamespaces(ret); if (xsltParseStylesheetProcess(ret, doc) == NULL) { ret->doc = NULL; @@ -2016,7 +2018,7 @@ xsltStylesheetPtr xsltParseStylesheetDoc(xmlDocPtr doc) { xsltStylesheetPtr ret; - ret = xsltParseStylesheetImportedDoc(doc); + ret = xsltParseStylesheetImportedDoc(doc, NULL); if (ret == NULL) return(NULL); diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h index 7e37959c..5cf478b0 100644 --- a/libxslt/xsltInternals.h +++ b/libxslt/xsltInternals.h @@ -572,7 +572,8 @@ XSLTPUBFUN void XSLTCALL XSLTPUBFUN xsltStylesheetPtr XSLTCALL xsltParseStylesheetDoc (xmlDocPtr doc); XSLTPUBFUN xsltStylesheetPtr XSLTCALL - xsltParseStylesheetImportedDoc(xmlDocPtr doc); + xsltParseStylesheetImportedDoc(xmlDocPtr doc, + xsltStylesheetPtr style); XSLTPUBFUN xsltStylesheetPtr XSLTCALL xsltLoadStylesheetPI (xmlDocPtr doc); XSLTPUBFUN void XSLTCALL diff --git a/python/libxsltclass.txt b/python/libxsltclass.txt index 0b88bb4a..11db84b5 100644 --- a/python/libxsltclass.txt +++ b/python/libxsltclass.txt @@ -32,7 +32,6 @@ loadStylesheetPI() newStylesheet() parseStylesheetDoc() parseStylesheetFile() -parseStylesheetImportedDoc() # functions from module xsltutils calibrateAdjust() @@ -179,10 +178,6 @@ Class stylesheet() freeNamespaceAliasHashes() namespaceAlias() - # functions from module pattern - cleanupTemplates() - freeTemplateHashes() - # functions from module preproc freeStylePreComps() stylePreCompute() @@ -198,6 +193,7 @@ Class stylesheet() # functions from module xsltInternals allocateExtra() freeStylesheet() + parseStylesheetImportedDoc() parseStylesheetOutput() parseStylesheetProcess() parseTemplateContent()