Skip to content

Commit 5c55306

Browse files
authored
Fix GH-14652: segfault on node without document. (#14653)
do not bother trying to clone the inner document if there is none to begin with.
1 parent 835cb69 commit 5c55306

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
@@ -600,7 +600,9 @@ static zend_object *dom_objects_store_clone_obj(zend_object *zobject) /* {{{ */
600600
if (cloned_node != NULL) {
601601
dom_update_refcount_after_clone(intern, node, clone, cloned_node);
602602
}
603-
clone->document->private_data = php_dom_libxml_ns_mapper_header(ns_mapper);
603+
if (ns_mapper != NULL) {
604+
clone->document->private_data = php_dom_libxml_ns_mapper_header(ns_mapper);
605+
}
604606
}
605607
}
606608

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)