Skip to content

Commit fddd0ac

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #66783: UAF when appending DOMDocument to element
2 parents c7fadd2 + a08847a commit fddd0ac

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2021, PHP 8.0.5
44

5+
- DOM:
6+
. Fixed bug #66783 (UAF when appending DOMDocument to element). (cmb)
7+
58
- FFI:
69
. Fixed bug #80847 (CData structs with fields of type struct can't be passed
710
as C function argument). (Nickolas Daniel da Silva, Dmitry)

ext/dom/php_dom.c

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

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

12501254
nodep = parent;
12511255

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)