From 88be50bf3939003b7146f49cf9bce092daa9d4b9 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 15 Aug 2020 10:52:04 +0200 Subject: [PATCH] Fix #79968: Manipulation on unattached DOMChildNode should throw DOMException --- ext/dom/parentnode.c | 5 +++++ ext/dom/tests/bug79968.phpt | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 ext/dom/tests/bug79968.phpt diff --git a/ext/dom/parentnode.c b/ext/dom/parentnode.c index a7627cb84c1c..f47416edff3d 100644 --- a/ext/dom/parentnode.c +++ b/ext/dom/parentnode.c @@ -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 index 000000000000..45107351a4eb --- /dev/null +++ b/ext/dom/tests/bug79968.phpt @@ -0,0 +1,17 @@ +--TEST-- +dom: Bug #79968 - Crash when calling before without valid hierachy +--SKIPIF-- + +--FILE-- +before("string"); +} catch (DOMException $e) { + echo $e->getMessage(); +} +?> +--EXPECT-- +Hierarchy Request Error