File tree 3 files changed +33
-7
lines changed 3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ PHP NEWS
37
37
. Fix weird unpack behaviour in DOM. (nielsdos)
38
38
. Fixed bug GH-18090 (DOM: Svg attributes and tag names are being lowercased).
39
39
(nielsdos)
40
+ . Fix xinclude destruction of live attributes. (nielsdos)
40
41
41
42
- Fuzzer:
42
43
. 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)
1669
1669
}
1670
1670
/* }}} end dom_document_savexml */
1671
1671
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
+
1672
1682
static void dom_xinclude_strip_references (xmlNodePtr basep )
1673
1683
{
1674
1684
php_libxml_node_free_resource (basep );
1685
+ dom_xinclude_strip_references_for_attributes (basep );
1675
1686
1676
1687
xmlNodePtr current = basep -> children ;
1677
1688
1678
1689
while (current ) {
1679
1690
php_libxml_node_free_resource (current );
1691
+ if (current -> type == XML_ELEMENT_NODE ) {
1692
+ dom_xinclude_strip_references_for_attributes (current );
1693
+ }
1680
1694
current = php_dom_next_in_tree_order (current , basep );
1681
1695
}
1682
1696
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ $doc->loadXML(<<<XML
13
13
</xi:include>
14
14
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
15
15
<xi:include href="thisisnonexistent">
16
- <p>garbage</p>
16
+ <p attr="foo" attr2="bar" >garbage</p>
17
17
</xi:include>
18
18
</xi:test>
19
19
</root>
@@ -22,20 +22,31 @@ XML);
22
22
$ xpath = new DOMXPath ($ doc );
23
23
24
24
$ garbage = [];
25
- foreach ($ xpath ->query ('//p ' ) as $ entry )
25
+ foreach ($ xpath ->query ('//p ' ) as $ entry ) {
26
26
$ garbage [] = $ entry ;
27
+ foreach ($ entry ->attributes as $ attr ) {
28
+ $ garbage [] = $ attr ;
29
+ foreach ($ attr ->childNodes as $ child ) {
30
+ $ garbage [] = $ child ;
31
+ }
32
+ }
33
+ }
27
34
28
35
@$ doc ->xinclude ();
29
36
30
37
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
+ }
36
43
}
37
44
?>
38
45
--EXPECT--
39
46
Invalid State Error
40
47
Invalid State Error
41
48
Invalid 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