From 2c2b427b7ac06a8d5d30cd48c9b179cd8051b5ba Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 24 Jun 2024 18:32:32 +0100 Subject: [PATCH] Fix GH-14652: segfault on node without document. do not bother trying to clone the inner document if there is none to begin with. --- ext/dom/php_dom.c | 4 +++- ext/dom/tests/gh14652.phpt | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 ext/dom/tests/gh14652.phpt diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 3e90db31db7e3..af3f86c81dfb2 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -598,7 +598,9 @@ static zend_object *dom_objects_store_clone_obj(zend_object *zobject) /* {{{ */ if (cloned_node != NULL) { dom_update_refcount_after_clone(intern, node, clone, cloned_node); } - clone->document->private_data = php_dom_libxml_ns_mapper_header(ns_mapper); + if (ns_mapper != NULL) { + clone->document->private_data = php_dom_libxml_ns_mapper_header(ns_mapper); + } } } diff --git a/ext/dom/tests/gh14652.phpt b/ext/dom/tests/gh14652.phpt new file mode 100644 index 0000000000000..2203bbbca1a0b --- /dev/null +++ b/ext/dom/tests/gh14652.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-14652 segfault on object cloning +--EXTENSIONS-- +dom +--CREDITS-- +YuanchengJiang +--FILE-- +value = "hello"; + +var_dump($attr->value); +var_dump($clone->value); +?> +--EXPECT-- +string(5) "hello" +string(5) "books"