Skip to content

Commit 9f6820f

Browse files
committed
Fix #79968: Manipulation on unattached DOMChildNode should throw DOMException
1 parent 736c5dc commit 9f6820f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ext/dom/parentnode.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNod
134134
dom_object *newNodeObj;
135135
int stricterror;
136136

137+
if (document == NULL) {
138+
php_dom_throw_error(HIERARCHY_REQUEST_ERR, 1);
139+
return NULL;
140+
}
141+
137142
if (contextNode->type == XML_DOCUMENT_NODE || contextNode->type == XML_HTML_DOCUMENT_NODE) {
138143
documentNode = (xmlDoc *) contextNode;
139144
} else {

ext/dom/tests/bug79968.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
dom: Bug #79968 - Crash when calling before without valid hierachy
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$cdata = new DOMText;
9+
10+
try {
11+
$cdata->before("string");
12+
} catch (DOMException $e) {
13+
echo $e->getMessage();
14+
}
15+
?>
16+
--EXPECT--
17+
Hierarchy Request Error

0 commit comments

Comments
 (0)