Skip to content

Commit e65f705

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #66783: UAF when appending DOMDocument to element
2 parents 709e45d + fddd0ac commit e65f705

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

ext/dom/php_dom.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,9 +1241,13 @@ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child)
12411241
{
12421242
xmlNodePtr nodep;
12431243

1244-
if (parent == NULL || child == NULL || child->doc != parent->doc) {
1245-
return SUCCESS;
1246-
}
1244+
if (parent == NULL || child == NULL || child->doc != parent->doc) {
1245+
return SUCCESS;
1246+
}
1247+
1248+
if (child->type == XML_DOCUMENT_NODE) {
1249+
return FAILURE;
1250+
}
12471251

12481252
nodep = parent;
12491253

ext/dom/tests/bug66783.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #66783 (UAF when appending DOMDocument to element)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('dom')) die('skip dom extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$doc = new DomDocument;
10+
$doc->loadXML('<root></root>');
11+
$e = $doc->createElement('e');
12+
try {
13+
$e->appendChild($doc);
14+
} catch (DOMException $ex) {
15+
echo $ex->getMessage(), PHP_EOL;
16+
}
17+
?>
18+
--EXPECTF--
19+
Hierarchy Request Error

0 commit comments

Comments
 (0)