Skip to content

Commit c11b23c

Browse files
committed
Fix bug #71540 - NULL pointer dereference in xsl_ext_function_php()
1 parent a3927fa commit c11b23c

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ PHP NEWS
3131
- Standard:
3232
. Fixed bug #70720 (strip_tags improper php code parsing). (Julien)
3333

34+
- XSL:
35+
. Fixed bug #71540 (NULL pointer dereference in xsl_ext_function_php()).
36+
(Stas)
37+
3438
- Zip:
3539
. Fixed bug #71561 (NULL pointer dereference in Zip::ExtractTo). (Laruence)
3640

ext/xsl/tests/bug71540.phpt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
--TEST--
2+
Bug #71540 (NULL pointer dereference in xsl_ext_function_php())
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('xsl')) die("skip Extension XSL is required\n");
6+
?>
7+
--FILE--
8+
<?php
9+
$xml = <<<EOB
10+
<allusers>
11+
<user>
12+
<uid>bob</uid>
13+
</user>
14+
</allusers>
15+
EOB;
16+
$xsl = <<<EOB
17+
<?xml version="1.0" encoding="UTF-8"?>
18+
<xsl:stylesheet version="1.0"
19+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20+
xmlns:php="http://php.net/xsl">
21+
<xsl:output method="html" encoding="utf-8" indent="yes"/>
22+
<xsl:template match="allusers">
23+
<html><body>
24+
<h2>Users</h2>
25+
<table>
26+
<xsl:for-each select="user">
27+
<tr><td>
28+
<xsl:value-of
29+
select="php:function('test',uid,test(test))"/>
30+
</td></tr>
31+
</xsl:for-each>
32+
</table>
33+
</body></html>
34+
</xsl:template>
35+
</xsl:stylesheet>
36+
EOB;
37+
38+
$xmldoc = new DOMDocument();
39+
$xmldoc->loadXML($xml);
40+
$xsldoc = new DOMDocument();
41+
$xsldoc->loadXML($xsl);
42+
43+
$proc = new XSLTProcessor();
44+
$proc->registerPHPFunctions();
45+
$proc->importStyleSheet($xsldoc);
46+
echo $proc->transformToXML($xmldoc);
47+
?>
48+
DONE
49+
--EXPECTF--
50+
Warning: XSLTProcessor::transformToXml(): xmlXPathCompOpEval: function test not found in %sbug71540.php on line %d
51+
52+
Warning: XSLTProcessor::transformToXml(): Unregistered function in %sbug71540.php on line %d
53+
54+
Warning: XSLTProcessor::transformToXml(): Stack usage errror in %sbug71540.php on line %d
55+
56+
Warning: XSLTProcessor::transformToXml(): Stack usage errror in %sbug71540.php on line %d
57+
58+
Warning: XSLTProcessor::transformToXml(): xmlXPathCompiledEval: 2 objects left on the stack. in %sbug71540.php on line %d
59+
60+
Warning: XSLTProcessor::transformToXml(): runtime error: file %s line 13 element value-of in %sbug71540.php on line %d
61+
62+
Warning: XSLTProcessor::transformToXml(): XPath evaluation returned no result. in %sbug71540.php on line %d
63+
<html xmlns:php="http://php.net/xsl"><body>
64+
<h2>Users</h2>
65+
<table><tr><td></td></tr></table>
66+
</body></html>
67+
DONE

ext/xsl/xsltprocessor.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t
239239
for (i = nargs - 2; i >= 0; i--) {
240240
obj = valuePop(ctxt);
241241
MAKE_STD_ZVAL(args[i]);
242+
if (obj == NULL) {
243+
ZVAL_NULL(args[i]);
244+
continue;
245+
}
242246
switch (obj->type) {
243247
case XPATH_STRING:
244248
ZVAL_STRING(args[i], obj->stringval, 1);

0 commit comments

Comments
 (0)