mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix #66783: UAF when appending DOMDocument to element
According to the DOM standard, elements may only contain element, text, processing instruction and comment nodes[1]. It is also specified that a HierarchyRequestError should be thrown if a document is to be inserted[2]. We follow that standard, and prevent the use-after-free this way. [1] <https://dom.spec.whatwg.org/#node-trees> [2] <https://dom.spec.whatwg.org/#mutation-algorithms> Closes GH-6765.
This commit is contained in:
parent
4adc08a403
commit
a08847ab39
3 changed files with 28 additions and 3 deletions
2
NEWS
2
NEWS
|
@ -2,6 +2,8 @@ PHP NEWS
|
|||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
?? ??? 2021, PHP 7.4.18
|
||||
|
||||
- DOM:
|
||||
. Fixed bug #66783 (UAF when appending DOMDocument to element). (cmb)
|
||||
|
||||
01 Apr 2021, PHP 7.4.17
|
||||
|
||||
|
|
|
@ -1302,9 +1302,13 @@ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child)
|
|||
{
|
||||
xmlNodePtr nodep;
|
||||
|
||||
if (parent == NULL || child == NULL || child->doc != parent->doc) {
|
||||
return SUCCESS;
|
||||
}
|
||||
if (parent == NULL || child == NULL || child->doc != parent->doc) {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
if (child->type == XML_DOCUMENT_NODE) {
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
nodep = parent;
|
||||
|
||||
|
|
19
ext/dom/tests/bug66783.phpt
Normal file
19
ext/dom/tests/bug66783.phpt
Normal file
|
@ -0,0 +1,19 @@
|
|||
--TEST--
|
||||
Bug #66783 (UAF when appending DOMDocument to element)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('dom')) die('skip dom extension not available');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$doc = new DomDocument;
|
||||
$doc->loadXML('<root></root>');
|
||||
$e = $doc->createElement('e');
|
||||
try {
|
||||
$e->appendChild($doc);
|
||||
} catch (DOMException $ex) {
|
||||
echo $ex->getMessage(), PHP_EOL;
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Hierarchy Request Error
|
Loading…
Add table
Add a link
Reference in a new issue