Skip to content

Commit 043b9e1

Browse files
committed
Fix GH-16039: Segmentation fault (access null pointer) in ext/dom/parentnode/tree.c
dom_object_get_node() can fail if we don't have a user object associated. Closes GH-16056.
1 parent 5feb29e commit 043b9e1

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
@@ -12,6 +12,10 @@ PHP NEWS
1212
. Fixed regression where signs after the first one were ignored while parsing
1313
a signed integer, with the DateTimeInterface::modify() function. (Derick)
1414

15+
- DOM:
16+
. Fixed bug GH-16039 (Segmentation fault (access null pointer) in
17+
ext/dom/parentnode/tree.c). (nielsdos)
18+
1519
- PHPDBG:
1620
. Fixed bug GH-15901 (phpdbg: Assertion failure on i funcs). (cmb)
1721

ext/dom/parentnode.c

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

275+
if (!node) {
276+
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
277+
return FAILURE;
278+
}
279+
275280
if (node->doc != documentNode) {
276281
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(document));
277282
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)