[libxslt] Also fix memory hazards in exsltFuncResultElem



commit 2fc326e8061461c73477aca2cace4b21a72ac972
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Tue Aug 29 23:52:37 2017 +0200

    Also fix memory hazards in exsltFuncResultElem
    
    Similar to the previous fix to exsltFuncFunctionFunction,
    exsltFuncResultElem also has to get the current node from the transform
    context instead of the XPath context.
    
    Thanks to Nicolas Gregoire for the report.
    
    Fixes bug 786989.

 libexslt/functions.c      |    3 ++-
 tests/general/bug-207.out |    2 +-
 tests/general/bug-207.xsl |   44 +++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/libexslt/functions.c b/libexslt/functions.c
index 5fd48bc..3f4e92c 100644
--- a/libexslt/functions.c
+++ b/libexslt/functions.c
@@ -714,6 +714,7 @@ exsltFuncResultElem (xsltTransformContextPtr ctxt,
 
        ctxt->xpathCtxt->namespaces = comp->nsList;
        ctxt->xpathCtxt->nsNr = comp->nsNr;
+        ctxt->xpathCtxt->node = ctxt->node;
 
        ret = xmlXPathCompiledEval(comp->select, ctxt->xpathCtxt);
 
@@ -752,7 +753,7 @@ exsltFuncResultElem (xsltTransformContextPtr ctxt,
 
        oldInsert = ctxt->insert;
        ctxt->insert = (xmlNodePtr) container;
-       xsltApplyOneTemplate (ctxt, ctxt->xpathCtxt->node,
+       xsltApplyOneTemplate (ctxt, ctxt->node,
                              inst->children, NULL, NULL);
        ctxt->insert = oldInsert;
 
diff --git a/tests/general/bug-207.out b/tests/general/bug-207.out
index 832a29e..8af83fb 100644
--- a/tests/general/bug-207.out
+++ b/tests/general/bug-207.out
@@ -1,2 +1,2 @@
 <?xml version="1.0"?>
-1
+111
diff --git a/tests/general/bug-207.xsl b/tests/general/bug-207.xsl
index 8fe6c61..121fe9d 100644
--- a/tests/general/bug-207.xsl
+++ b/tests/general/bug-207.xsl
@@ -3,21 +3,59 @@
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:f="http://exslt.org/functions";
   extension-element-prefixes="f">
-  <f:function name="f:f">
+
+  <f:function name="f:f1">
     <xsl:param name="n"/>
     <xsl:for-each select="namespace::*">
       <xsl:sort/>
     </xsl:for-each>
     <xsl:choose>
         <xsl:when test="$n > 0">
-            <f:result select="f:f($n - 1)"/>
+            <f:result select="f:f1($n - 1)"/>
         </xsl:when>
         <xsl:otherwise>
             <f:result select="1"/>
         </xsl:otherwise>
     </xsl:choose>
   </f:function>
+
+  <f:function name="f:f2">
+    <xsl:for-each select="namespace::*">
+      <xsl:sort/>
+    </xsl:for-each>
+    <f:result select="1"/>
+  </f:function>
+
+  <f:function name="f:f3">
+    <xsl:for-each select="namespace::*">
+      <xsl:sort/>
+    </xsl:for-each>
+    <f:result>
+      <xsl:number/>
+    </f:result>
+  </f:function>
+
+  <f:function name="f:f4">
+    <xsl:for-each select="namespace::*">
+      <xsl:sort/>
+    </xsl:for-each>
+    <f:result>
+      <xsl:apply-templates/>
+    </f:result>
+  </f:function>
+
+  <f:function name="f:f5">
+    <xsl:for-each select="namespace::*">
+      <xsl:sort/>
+    </xsl:for-each>
+    <f:result select="key('xxx', 'yyy')"/>
+  </f:function>
+
   <xsl:template match="/*">
-    <xsl:value-of select="f:f(4)"/>
+    <xsl:value-of select="f:f1(4)"/>
+    <xsl:value-of select="f:f2()"/>
+    <xsl:value-of select="f:f3()"/>
+    <xsl:value-of select="f:f4()"/>
+    <xsl:value-of select="f:f5()"/>
   </xsl:template>
 </xsl:stylesheet>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]