Skip to content

Commit 4ee275f

Browse files
committed
Fix GH-21548: Dom\XMLDocument::C14N() emits duplicate xmlns declarations after setAttributeNS().
The xmlns attribute unlinking code in dom_relink_ns_decls_element was clobbering attr->prev instead of updating the predecessor's next pointer, leaving non-first xmlns attributes reachable in the properties list. C14N then output them both as nsDef entries and as attributes. close GH-21566
1 parent 86c4877 commit 4ee275f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug GH-19983 (GC assertion failure with fibers, generators and
77
destructors). (iliaal)
88

9+
- DOM:
10+
. Fixed bug GH-21566 (Dom\XMLDocument::C14N() emits duplicate xmlns
11+
declarations after setAttributeNS()). (David Carlier)
12+
913
- SPL:
1014
. Fixed bug GH-21499 (RecursiveArrayIterator getChildren UAF after parent
1115
free). (Girgias)

ext/dom/node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ static void dom_relink_ns_decls_element(HashTable *links, xmlNodePtr node)
21322132

21332133
ns->_private = attr;
21342134
if (attr->prev) {
2135-
attr->prev = attr->next;
2135+
attr->prev->next = attr->next;
21362136
} else {
21372137
node->properties = attr->next;
21382138
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-21548 (Dom\XMLDocument::C14N() emits duplicate xmlns declarations after setAttributeNS())
3+
--CREDITS--
4+
Toon Verwerft (veewee)
5+
--EXTENSIONS--
6+
dom
7+
--FILE--
8+
<?php
9+
10+
$doc = Dom\XMLDocument::createFromString('<root xmlns="urn:a" attr="val"/>');
11+
$doc->documentElement->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:ns1", "urn:a");
12+
13+
echo $doc->C14N() . PHP_EOL;
14+
15+
?>
16+
--EXPECT--
17+
<root xmlns="urn:a" xmlns:ns1="urn:a" attr="val"></root>

0 commit comments

Comments
 (0)