Skip to content

Commit 2c2b427

Browse files
committed
Fix GH-14652: segfault on node without document.
do not bother trying to clone the inner document if there is none to begin with.
1 parent ab9a029 commit 2c2b427

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ext/dom/php_dom.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,9 @@ static zend_object *dom_objects_store_clone_obj(zend_object *zobject) /* {{{ */
598598
if (cloned_node != NULL) {
599599
dom_update_refcount_after_clone(intern, node, clone, cloned_node);
600600
}
601-
clone->document->private_data = php_dom_libxml_ns_mapper_header(ns_mapper);
601+
if (ns_mapper != NULL) {
602+
clone->document->private_data = php_dom_libxml_ns_mapper_header(ns_mapper);
603+
}
602604
}
603605
}
604606

ext/dom/tests/gh14652.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-14652 segfault on object cloning
3+
--EXTENSIONS--
4+
dom
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
$attr = new DOMAttr('category', 'books');
10+
$clone = clone $attr;
11+
$attr->value = "hello";
12+
13+
var_dump($attr->value);
14+
var_dump($clone->value);
15+
?>
16+
--EXPECT--
17+
string(5) "hello"
18+
string(5) "books"

0 commit comments

Comments
 (0)