]> granicus.if.org Git - php/commitdiff
Fix #79968: Manipulation on unattached DOMChildNode should throw DOMException
authorBenjamin Eberlei <kontakt@beberlei.de>
Sat, 15 Aug 2020 08:52:04 +0000 (10:52 +0200)
committerBenjamin Eberlei <kontakt@beberlei.de>
Wed, 19 Aug 2020 09:54:41 +0000 (11:54 +0200)
ext/dom/parentnode.c
ext/dom/tests/bug79968.phpt [new file with mode: 0644]

index a7627cb84c1cb2a6cbcc92c5147accbe24933429..f47416edff3dd9fb666a0f46197ee2b3e097a033 100644 (file)
@@ -134,6 +134,11 @@ xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNod
        dom_object *newNodeObj;
        int stricterror;
 
+       if (document == NULL) {
+               php_dom_throw_error(HIERARCHY_REQUEST_ERR, 1);
+               return NULL;
+       }
+
        if (contextNode->type == XML_DOCUMENT_NODE || contextNode->type == XML_HTML_DOCUMENT_NODE) {
                documentNode = (xmlDoc *) contextNode;
        } else {
diff --git a/ext/dom/tests/bug79968.phpt b/ext/dom/tests/bug79968.phpt
new file mode 100644 (file)
index 0000000..4510735
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+dom: Bug #79968 - Crash when calling before without valid hierachy
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+$cdata = new DOMText;
+
+try {
+    $cdata->before("string");
+} catch (DOMException $e) {
+    echo $e->getMessage();
+}
+?>
+--EXPECT--
+Hierarchy Request Error