File tree Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Original file line number Diff line number Diff 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).
Original file line number Diff line number Diff 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+
16721682static 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}
Original file line number Diff line number Diff 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
3037foreach ($ 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--
3946Invalid State Error
4047Invalid State Error
4148Invalid State Error
49+ Invalid State Error
50+ Invalid State Error
51+ Invalid State Error
52+ Invalid State Error
You can’t perform that action at this time.
0 commit comments