Skip to content

Commit 2c45d67

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix xinclude destruction of live attributes
2 parents 5684199 + d9329b1 commit 2c45d67

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ PHP NEWS
3737
. Fix weird unpack behaviour in DOM. (nielsdos)
3838
. Fixed bug GH-18090 (DOM: Svg attributes and tag names are being lowercased).
3939
(nielsdos)
40+
. Fix xinclude destruction of live attributes. (nielsdos)
4041

4142
- Fuzzer:
4243
. Fixed bug GH-18081 (Memory leaks in error paths of fuzzer SAPI).

ext/dom/document.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,14 +1669,28 @@ PHP_METHOD(Dom_XMLDocument, saveXml)
16691669
}
16701670
/* }}} end dom_document_savexml */
16711671

1672+
static void dom_xinclude_strip_references_for_attributes(xmlNodePtr basep)
1673+
{
1674+
for (xmlAttrPtr prop = basep->properties; prop; prop = prop->next) {
1675+
php_libxml_node_free_resource((xmlNodePtr) prop);
1676+
for (xmlNodePtr child = prop->children; child; child = child->next) {
1677+
php_libxml_node_free_resource(child);
1678+
}
1679+
}
1680+
}
1681+
16721682
static void dom_xinclude_strip_references(xmlNodePtr basep)
16731683
{
16741684
php_libxml_node_free_resource(basep);
1685+
dom_xinclude_strip_references_for_attributes(basep);
16751686

16761687
xmlNodePtr current = basep->children;
16771688

16781689
while (current) {
16791690
php_libxml_node_free_resource(current);
1691+
if (current->type == XML_ELEMENT_NODE) {
1692+
dom_xinclude_strip_references_for_attributes(current);
1693+
}
16801694
current = php_dom_next_in_tree_order(current, basep);
16811695
}
16821696
}

ext/dom/tests/gh17847.phpt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $doc->loadXML(<<<XML
1313
</xi:include>
1414
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
1515
<xi:include href="thisisnonexistent">
16-
<p>garbage</p>
16+
<p attr="foo" attr2="bar">garbage</p>
1717
</xi:include>
1818
</xi:test>
1919
</root>
@@ -22,20 +22,31 @@ XML);
2222
$xpath = new DOMXPath($doc);
2323

2424
$garbage = [];
25-
foreach ($xpath->query('//p') as $entry)
25+
foreach ($xpath->query('//p') as $entry) {
2626
$garbage[] = $entry;
27+
foreach ($entry->attributes as $attr) {
28+
$garbage[] = $attr;
29+
foreach ($attr->childNodes as $child) {
30+
$garbage[] = $child;
31+
}
32+
}
33+
}
2734

2835
@$doc->xinclude();
2936

3037
foreach ($garbage as $node) {
31-
try {
32-
var_dump($node->localName);
33-
} catch (DOMException $e) {
34-
echo $e->getMessage(), "\n";
35-
}
38+
try {
39+
var_dump($node->localName);
40+
} catch (DOMException $e) {
41+
echo $e->getMessage(), "\n";
42+
}
3643
}
3744
?>
3845
--EXPECT--
3946
Invalid State Error
4047
Invalid State Error
4148
Invalid State Error
49+
Invalid State Error
50+
Invalid State Error
51+
Invalid State Error
52+
Invalid State Error

0 commit comments

Comments
 (0)