diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 27ec683910057..55779f2e9ba06 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -600,7 +600,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"