Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ PHP NEWS
- DOM:
. Fixed a use-after-free when cloning a DOMNameSpaceNode after
DOMDocument::xinclude(). (iliaal)
. Fixed a use-after-free when Dom\Element::setAttributeNS() replaces the
value of an attribute whose child still has a live wrapper. (iliaal)

- Intl:
. Fixed a double-free when IntlGregorianCalendar construction fails after
Expand Down
4 changes: 4 additions & 0 deletions ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,10 @@ static void dom_set_attribute_ns_modern(dom_object *intern, xmlNodePtr elemp, ze
if (errorcode == 0) {
php_dom_libxml_ns_mapper *ns_mapper = php_dom_get_ns_mapper(intern);
xmlNsPtr ns = php_dom_libxml_ns_mapper_get_ns_raw_prefix_string(ns_mapper, prefix, xmlStrlen(prefix), uri);
xmlNodePtr existing = (xmlNodePtr) xmlHasNsProp(elemp, localname, ns == NULL ? NULL : ns->href);
if (existing != NULL && existing->type != XML_ATTRIBUTE_DECL) {
node_list_unlink(existing->children);
}
xmlAttrPtr attr = xmlSetNsProp(elemp, ns, localname, BAD_CAST value);
if (UNEXPECTED(attr == NULL)) {
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
setAttributeNS() keeps an attribute child that still has a live wrapper
--EXTENSIONS--
dom
--FILE--
<?php

$doc = Dom\XMLDocument::createFromString('<root xmlns:p="urn:x" p:attr="old"/>');
$el = $doc->documentElement;
$text = $el->getAttributeNodeNS('urn:x', 'attr')->firstChild;
$el->setAttributeNS('urn:x', 'p:attr', 'new');
echo "prefixed, detached: ";
var_dump($text->parentNode === null);
echo "prefixed, text: ";
var_dump($text->textContent);
echo "prefixed, new value: ";
var_dump($el->getAttributeNS('urn:x', 'attr'));

$doc = Dom\XMLDocument::createFromString('<root attr="old"/>');
$el = $doc->documentElement;
$text = $el->getAttributeNode('attr')->firstChild;
$el->setAttributeNS(null, 'attr', 'new');
echo "no namespace, detached: ";
var_dump($text->parentNode === null);
echo "no namespace, text: ";
var_dump($text->textContent);
echo "no namespace, new value: ";
var_dump($el->getAttribute('attr'));

?>
--EXPECT--
prefixed, detached: bool(true)
prefixed, text: string(3) "old"
prefixed, new value: string(3) "new"
no namespace, detached: bool(true)
no namespace, text: string(3) "old"
no namespace, new value: string(3) "new"
Loading