Skip to content

Commit edbd26a

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/dom: Reject DTD declaration nodes in adoptNode()
2 parents 2a407fb + 5835cf2 commit edbd26a

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ PHP NEWS
6363
node map iterator that has no current item. (Ilia Alshanetsky)
6464
. Fixed use-after-free in getElementById() after a removed ID attribute is
6565
freed. (Ilia Alshanetsky)
66+
. Fixed bug GH-25750 (adoptNode() accepts DTD declaration nodes, which can
67+
crash at document teardown). (Ian Mattas)
6668

6769
- FFI:
6870
. Fixed bug GH-25558 (struct with an enum field passed by value is described

‎ext/dom/document.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,9 @@ static void dom_document_adopt_node(INTERNAL_FUNCTION_PARAMETERS, bool modern)
12121212
|| nodep->type == XML_DOCUMENT_TYPE_NODE
12131213
|| nodep->type == XML_DTD_NODE
12141214
|| nodep->type == XML_ENTITY_NODE
1215+
|| nodep->type == XML_ELEMENT_DECL
1216+
|| nodep->type == XML_ATTRIBUTE_DECL
1217+
|| nodep->type == XML_ENTITY_DECL
12151218
|| nodep->type == XML_NOTATION_NODE)) {
12161219
php_dom_throw_error(NOT_SUPPORTED_ERR, dom_get_strict_error(dom_object_nodep->document));
12171220
RETURN_FALSE;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Dom\Document::adoptNode() rejects DTD declarations
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$xml = '<!DOCTYPE root [<!ELEMENT root EMPTY><!ENTITY ent "value">]><root/>';
8+
$source = Dom\XMLDocument::createFromString($xml);
9+
$target = Dom\XMLDocument::createFromString('<target/>');
10+
11+
$nodes = [
12+
$source->doctype->childNodes->item(0),
13+
$source->doctype->entities->item(0),
14+
];
15+
16+
foreach ($nodes as $node) {
17+
try {
18+
$target->adoptNode($node);
19+
echo "adopted\n";
20+
} catch (DOMException $e) {
21+
echo $e::class, ": ", $e->getCode(), "\n";
22+
}
23+
}
24+
?>
25+
--EXPECT--
26+
DOMException: 9
27+
DOMException: 9

0 commit comments

Comments
 (0)