Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix xinclude destruction of live attributes
This commit is contained in:
Niels Dossche 2025-03-18 22:03:12 +01:00
commit 2c45d67ad3
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
3 changed files with 33 additions and 7 deletions

1
NEWS
View file

@ -37,6 +37,7 @@ PHP NEWS
. Fix weird unpack behaviour in DOM. (nielsdos) . Fix weird unpack behaviour in DOM. (nielsdos)
. Fixed bug GH-18090 (DOM: Svg attributes and tag names are being lowercased). . Fixed bug GH-18090 (DOM: Svg attributes and tag names are being lowercased).
(nielsdos) (nielsdos)
. Fix xinclude destruction of live attributes. (nielsdos)
- Fuzzer: - Fuzzer:
. Fixed bug GH-18081 (Memory leaks in error paths of fuzzer SAPI). . Fixed bug GH-18081 (Memory leaks in error paths of fuzzer SAPI).

View file

@ -1669,14 +1669,28 @@ PHP_METHOD(Dom_XMLDocument, saveXml)
} }
/* }}} end dom_document_savexml */ /* }}} end dom_document_savexml */
static void dom_xinclude_strip_references_for_attributes(xmlNodePtr basep)
{
for (xmlAttrPtr prop = basep->properties; prop; prop = prop->next) {
php_libxml_node_free_resource((xmlNodePtr) prop);
for (xmlNodePtr child = prop->children; child; child = child->next) {
php_libxml_node_free_resource(child);
}
}
}
static void dom_xinclude_strip_references(xmlNodePtr basep) static void dom_xinclude_strip_references(xmlNodePtr basep)
{ {
php_libxml_node_free_resource(basep); php_libxml_node_free_resource(basep);
dom_xinclude_strip_references_for_attributes(basep);
xmlNodePtr current = basep->children; xmlNodePtr current = basep->children;
while (current) { while (current) {
php_libxml_node_free_resource(current); php_libxml_node_free_resource(current);
if (current->type == XML_ELEMENT_NODE) {
dom_xinclude_strip_references_for_attributes(current);
}
current = php_dom_next_in_tree_order(current, basep); current = php_dom_next_in_tree_order(current, basep);
} }
} }

View file

@ -13,7 +13,7 @@ $doc->loadXML(<<<XML
</xi:include> </xi:include>
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="thisisnonexistent"> <xi:include href="thisisnonexistent">
<p>garbage</p> <p attr="foo" attr2="bar">garbage</p>
</xi:include> </xi:include>
</xi:test> </xi:test>
</root> </root>
@ -22,8 +22,15 @@ XML);
$xpath = new DOMXPath($doc); $xpath = new DOMXPath($doc);
$garbage = []; $garbage = [];
foreach ($xpath->query('//p') as $entry) foreach ($xpath->query('//p') as $entry) {
$garbage[] = $entry; $garbage[] = $entry;
foreach ($entry->attributes as $attr) {
$garbage[] = $attr;
foreach ($attr->childNodes as $child) {
$garbage[] = $child;
}
}
}
@$doc->xinclude(); @$doc->xinclude();
@ -39,3 +46,7 @@ foreach ($garbage as $node) {
Invalid State Error Invalid State Error
Invalid State Error Invalid State Error
Invalid State Error Invalid State Error
Invalid State Error
Invalid State Error
Invalid State Error
Invalid State Error