Skip to content

Commit 68d494d

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-16039: Segmentation fault (access null pointer) in ext/dom/parentnode/tree.c
2 parents 4c03260 + 043b9e1 commit 68d494d

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.13
44

5+
- DOM:
6+
. Fixed bug GH-16039 (Segmentation fault (access null pointer) in
7+
ext/dom/parentnode/tree.c). (nielsdos)
8+
59
- PHPDBG:
610
. Fixed bug GH-15901 (phpdbg: Assertion failure on i funcs). (cmb)
711

ext/dom/parentnode.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ static zend_result dom_sanity_check_node_list_for_insertion(php_libxml_ref_obj *
265265
if (instanceof_function(ce, dom_node_class_entry)) {
266266
xmlNodePtr node = dom_object_get_node(Z_DOMOBJ_P(nodes + i));
267267

268+
if (!node) {
269+
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
270+
return FAILURE;
271+
}
272+
268273
if (node->doc != documentNode) {
269274
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(document));
270275
return FAILURE;

ext/dom/tests/gh16039.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
GH-16039 (Segmentation fault (access null pointer) in ext/dom/parentnode/tree.c)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = new DOMDocument;
9+
$element = $dom->appendChild($dom->createElement('root'));
10+
try {
11+
$element->prepend('x', new DOMEntity);
12+
} catch (DOMException $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
echo $dom->saveXML();
16+
$dom->strictErrorChecking = false; // Should not have influence
17+
try {
18+
$element->prepend('x', new DOMEntity);
19+
} catch (DOMException $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
echo $dom->saveXML();
23+
24+
?>
25+
--EXPECT--
26+
Invalid State Error
27+
<?xml version="1.0"?>
28+
<root/>
29+
Invalid State Error
30+
<?xml version="1.0"?>
31+
<root/>

0 commit comments

Comments
 (0)