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
5 changes: 5 additions & 0 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,11 @@ static bool dom_node_check_legacy_insertion_validity(xmlNodePtr parentp, xmlNode
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
return false;
}
/* Attributes must be in elements. */
if (child->type == XML_ATTRIBUTE_NODE && parentp->type != XML_ELEMENT_NODE) {
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
return false;
}

return true;
}
Expand Down
20 changes: 20 additions & 0 deletions ext/dom/tests/gh16533.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-16533 (Segfault when adding attribute to parent that is not an element)
--EXTENSIONS--
dom
--FILE--
<?php

$doc = new DOMDocument();
try {
$doc->appendChild($doc->createAttribute('foo'));
} catch (DOMException $e) {
echo $e->getMessage(), "\n";
}

echo $doc->saveXML();

?>
--EXPECT--
Hierarchy Request Error
<?xml version="1.0"?>
Loading