Skip to content

Commit df484b0

Browse files
committed
Merge branch 'PHP-5.6'
* PHP-5.6: BFN fix bug #49634x
2 parents f8148a3 + 733259c commit df484b0

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

ext/xsl/tests/bug49634.phpt

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
--TEST--
2+
bug #49634 (Segfault throwing an exception in a XSL registered function)
3+
--SKIPIF--
4+
<?php
5+
extension_loaded("xsl") or die("skip need ext/xsl");
6+
?>
7+
--FILE--
8+
<?php
9+
10+
$sXml = <<<XML
11+
<?xml version="1.0" encoding="UTF-8" ?>
12+
<root>
13+
test
14+
</root>
15+
XML;
16+
17+
$cDIR = __DIR__;
18+
$sXsl = <<<XSL
19+
<xsl:stylesheet version="1.0"
20+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21+
xmlns:ext="http://php.net/xsl"
22+
xsl:extension-element-prefixes="ext"
23+
exclude-result-prefixes="ext">
24+
<xsl:output encoding="UTF-8" indent="yes" method="xml" />
25+
<xsl:template match="/">
26+
<xsl:value-of select="ext:function('testFunction', document('$cDIR/bug49634.xml')/root)"/>
27+
</xsl:template>
28+
</xsl:stylesheet>
29+
XSL;
30+
31+
function testFunction($a)
32+
{
33+
throw new Exception('Test exception.');
34+
}
35+
36+
$domXml = new DOMDocument;
37+
$domXml->loadXML($sXml);
38+
$domXsl = new DOMDocument;
39+
$domXsl->loadXML($sXsl);
40+
41+
for ($i = 0; $i < 10; $i++)
42+
{
43+
$xsltProcessor = new XSLTProcessor();
44+
$xsltProcessor->registerPHPFunctions(array('testFunction'));
45+
$xsltProcessor->importStyleSheet($domXsl);
46+
try {
47+
@$xsltProcessor->transformToDoc($domXml);
48+
} catch (Exception $e) {
49+
echo $e,"\n";
50+
}
51+
}
52+
?>
53+
===DONE===
54+
--EXPECTF--
55+
exception 'Exception' with message 'Test exception.' in %s:%d
56+
Stack trace:
57+
#0 [internal function]: testFunction(Array)
58+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
59+
#2 {main}
60+
exception 'Exception' with message 'Test exception.' in %s:%d
61+
Stack trace:
62+
#0 [internal function]: testFunction(Array)
63+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
64+
#2 {main}
65+
exception 'Exception' with message 'Test exception.' in %s:%d
66+
Stack trace:
67+
#0 [internal function]: testFunction(Array)
68+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
69+
#2 {main}
70+
exception 'Exception' with message 'Test exception.' in %s:%d
71+
Stack trace:
72+
#0 [internal function]: testFunction(Array)
73+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
74+
#2 {main}
75+
exception 'Exception' with message 'Test exception.' in %s:%d
76+
Stack trace:
77+
#0 [internal function]: testFunction(Array)
78+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
79+
#2 {main}
80+
exception 'Exception' with message 'Test exception.' in %s:%d
81+
Stack trace:
82+
#0 [internal function]: testFunction(Array)
83+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
84+
#2 {main}
85+
exception 'Exception' with message 'Test exception.' in %s:%d
86+
Stack trace:
87+
#0 [internal function]: testFunction(Array)
88+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
89+
#2 {main}
90+
exception 'Exception' with message 'Test exception.' in %s:%d
91+
Stack trace:
92+
#0 [internal function]: testFunction(Array)
93+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
94+
#2 {main}
95+
exception 'Exception' with message 'Test exception.' in %s:%d
96+
Stack trace:
97+
#0 [internal function]: testFunction(Array)
98+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
99+
#2 {main}
100+
exception 'Exception' with message 'Test exception.' in %s:%d
101+
Stack trace:
102+
#0 [internal function]: testFunction(Array)
103+
#1 %s(%d): XSLTProcessor->transformToDoc(Object(DOMDocument))
104+
#2 {main}
105+
===DONE===

ext/xsl/tests/bug49634.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<root/>

ext/xsl/xsltprocessor.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t
279279
node->type = XML_NAMESPACE_DECL;
280280
node->parent = nsparent;
281281
node->ns = curns;
282+
} else {
283+
node = xmlDocCopyNodeList(domintern->document->ptr, node);
282284
}
285+
283286
child = php_dom_create_object(node, &ret, child, domintern TSRMLS_CC);
284287
add_next_index_zval(args[i], child);
285288
}

0 commit comments

Comments
 (0)