summaryrefslogtreecommitdiff
path: root/ext/dom/php_dom.c
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2021-03-15 10:26:50 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2021-03-17 12:37:18 +0100
commita08847ab39bb512d500cf196981a3e8780c83600 (patch)
tree70219b3bf0b7f8f0b90d7fcc8846d7bd174cf258 /ext/dom/php_dom.c
parent4adc08a403fe6784af0ca91c7743c3b5c44763a4 (diff)
downloadphp-git-a08847ab39bb512d500cf196981a3e8780c83600.tar.gz
Fix #66783: UAF when appending DOMDocument to element
According to the DOM standard, elements may only contain element, text, processing instruction and comment nodes[1]. It is also specified that a HierarchyRequestError should be thrown if a document is to be inserted[2]. We follow that standard, and prevent the use-after-free this way. [1] <https://dom.spec.whatwg.org/#node-trees> [2] <https://dom.spec.whatwg.org/#mutation-algorithms> Closes GH-6765.
Diffstat (limited to 'ext/dom/php_dom.c')
-rw-r--r--ext/dom/php_dom.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
index 6bc72e9f97..2f2878d5e1 100644
--- a/ext/dom/php_dom.c
+++ b/ext/dom/php_dom.c
@@ -1302,9 +1302,13 @@ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child)
{
xmlNodePtr nodep;
- if (parent == NULL || child == NULL || child->doc != parent->doc) {
- return SUCCESS;
- }
+ if (parent == NULL || child == NULL || child->doc != parent->doc) {
+ return SUCCESS;
+ }
+
+ if (child->type == XML_DOCUMENT_NODE) {
+ return FAILURE;
+ }
nodep = parent;