Skip to content
Open
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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ PHP NEWS
- DOM:
. Fix GH-22219 (Dom\XMLDocument::schemaValidate fails to resolve
xs:QName with prefix from imported schema). (David Carlier)
. Fixed bug GH-22447 (UAF at dom_objects_free_storage when setting an
attribute node that collides by local name with a namespaced
attribute). (David Carlier)

- Exif:
. Read correct value for single and double tags. (ndossche)
Expand Down
2 changes: 2 additions & 0 deletions ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ static void dom_element_set_attribute_node_common(INTERNAL_FUNCTION_PARAMETERS,
nsp = attrp->ns;
if (use_ns && nsp != NULL) {
existattrp = xmlHasNsProp(nodep, attrp->name, nsp->href);
} else if (nsp == NULL) {
existattrp = xmlHasNsProp(nodep, attrp->name, NULL);
} else {
existattrp = xmlHasProp(nodep, attrp->name);
}
Expand Down
6 changes: 3 additions & 3 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ static void dom_node_insert_before_legacy(zval *return_value, zval *ref, dom_obj
xmlAttrPtr lastattr;

if (child->ns == NULL)
lastattr = xmlHasProp(refp->parent, child->name);
lastattr = xmlHasNsProp(refp->parent, child->name, NULL);
else
lastattr = xmlHasNsProp(refp->parent, child->name, child->ns->href);
if (lastattr != NULL && lastattr->type != XML_ATTRIBUTE_DECL) {
Expand Down Expand Up @@ -1012,7 +1012,7 @@ static void dom_node_insert_before_legacy(zval *return_value, zval *ref, dom_obj
xmlAttrPtr lastattr;

if (child->ns == NULL)
lastattr = xmlHasProp(parentp, child->name);
lastattr = xmlHasNsProp(parentp, child->name, NULL);
else
lastattr = xmlHasNsProp(parentp, child->name, child->ns->href);
if (lastattr != NULL && lastattr->type != XML_ATTRIBUTE_DECL) {
Expand Down Expand Up @@ -1374,7 +1374,7 @@ static void dom_node_append_child_legacy(zval *return_value, dom_object *intern,
xmlAttrPtr lastattr;

if (child->ns == NULL)
lastattr = xmlHasProp(nodep, child->name);
lastattr = xmlHasNsProp(nodep, child->name, NULL);
else
lastattr = xmlHasNsProp(nodep, child->name, child->ns->href);
if (lastattr != NULL && lastattr->type != XML_ATTRIBUTE_DECL) {
Expand Down
25 changes: 25 additions & 0 deletions ext/dom/tests/gh22447.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
GH-22447 (UAF at dom_objects_free_storage when setAttributeNode collides with a namespaced attribute of the same local name)
--EXTENSIONS--
dom
--FILE--
<?php
$dom = Dom\HTMLDocument::createEmpty();

$attribute1 = $dom->createAttribute("my-attribute");
$container = $dom->appendChild($dom->createElement("container"));
$attribute2 = $dom->createAttribute("my-attribute");
$attribute4 = $dom->createAttributeNS("urn:a", "my-attribute");

$container->setAttributeNode($attribute1);
$container->setAttributeNode($attribute4);

var_dump($container->setAttributeNode($attribute2) === $attribute1);
var_dump($container->setAttributeNode($attribute1) === $attribute2);

echo $dom->saveXml($container), PHP_EOL;
?>
--EXPECT--
bool(true)
bool(true)
<container xmlns="http://www.w3.org/1999/xhtml" xmlns:ns1="urn:a" ns1:my-attribute="" my-attribute=""></container>
Loading