felipe          Sun May 10 15:13:05 2009 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/xsl/tests      bug48221.phpt 

  Modified files:              
    /php-src/ext/xsl    xsltprocessor.c 
  Log:
  - MFH: Fixed bug #48221 (memory leak when passing invalid xslt parameter)
  
http://cvs.php.net/viewvc.cgi/php-src/ext/xsl/xsltprocessor.c?r1=1.39.2.2.2.9.2.15&r2=1.39.2.2.2.9.2.16&diff_format=u
Index: php-src/ext/xsl/xsltprocessor.c
diff -u php-src/ext/xsl/xsltprocessor.c:1.39.2.2.2.9.2.15 
php-src/ext/xsl/xsltprocessor.c:1.39.2.2.2.9.2.16
--- php-src/ext/xsl/xsltprocessor.c:1.39.2.2.2.9.2.15   Wed Dec 31 11:15:47 2008
+++ php-src/ext/xsl/xsltprocessor.c     Sun May 10 15:13:05 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: xsltprocessor.c,v 1.39.2.2.2.9.2.15 2008/12/31 11:15:47 sebastian Exp 
$ */
+/* $Id: xsltprocessor.c,v 1.39.2.2.2.9.2.16 2009/05/10 15:13:05 felipe Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -153,11 +153,13 @@
                        if (!xpath_params) {
                                xpath_expr = 
php_xsl_xslt_string_to_xpathexpr(Z_STRVAL_PP(value) TSRMLS_CC);
                        } else {
-                               xpath_expr = estrndup(Z_STRVAL_PP(value), 
strlen(Z_STRVAL_PP(value)));
+                               xpath_expr = estrndup(Z_STRVAL_PP(value), 
Z_STRLEN_PP(value));
                        }
                        if (xpath_expr) {
                                params[i++] = string_key;
                                params[i++] = xpath_expr;
+                       } else {
+                               efree(string_key);
                        }
                }
        }

http://cvs.php.net/viewvc.cgi/php-src/ext/xsl/tests/bug48221.phpt?view=markup&rev=1.1
Index: php-src/ext/xsl/tests/bug48221.phpt
+++ php-src/ext/xsl/tests/bug48221.phpt
--TEST--
Bug #48221 (memory leak when passing invalid xslt parameter)
--SKIPIF--
<?php
if (!extension_loaded('xsl')) die("skip Extension XSL is required\n");
?>
--FILE--
<?php

$xsl = new DOMDocument;
$xsl->loadXML('<html xsl:version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
      lang="en">
    <head>
        <title>Sales Results By Division</title>
    </head>
    <body>
        <table border="1">
            <tr>
                <th>Division</th>
                <th>Revenue</th>
                <th>Growth</th>
                <th>Bonus</th>
            </tr>
            <xsl:for-each select="sales/division">
                <!-- order the result by revenue -->
                <xsl:sort select="revenue"
                          data-type="number"
                          order="descending"/>
                <tr>
                    <td>
                        <em><xsl:value-of select="@id"/></em>
                    </td>
                    <td>
                        <xsl:value-of select="revenue"/>
                    </td>
                    <td>
                        <!-- highlight negative growth in red -->
                        <xsl:if test="growth &lt; 0">
                             <xsl:attribute name="style">
                                 <xsl:text>color:red</xsl:text>
                             </xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="growth"/>
                    </td>
                    <td>
                        <xsl:value-of select="bonus"/>
                    </td>
                </tr>
            </xsl:for-each>
        </table>
    </body>
</html>');

$dom = new DOMDocument;
$dom->loadXMl('<sales>

        <division id="North">
                <revenue>10</revenue>
                <growth>9</growth>
                <bonus>7</bonus>
        </division>

        <division id="South">
                <revenue>4</revenue>
                <growth>3</growth>
                <bonus>4</bonus>
        </division>

        <division id="West">
                <revenue>6</revenue>
                <growth>-1.5</growth>
                <bonus>2</bonus>
        </division>

</sales>');

$proc = new xsltprocessor;
$proc->importStylesheet($xsl);
$proc->setParameter('', '', '"\'');
$proc->transformToXml($dom);

?>
--EXPECTF--
Warning: XSLTProcessor::transformToXml(): Cannot create XPath expression 
(string contains both quote and double-quotes) in %s on line %d



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to