Skip to content

Commit e5a5e41

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 e5a5e41

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ext/dom/php_dom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static zend_object *dom_objects_store_clone_obj(zend_object *zobject) /* {{{ */
584584

585585
if (instanceof_function(intern->std.ce, dom_node_class_entry) || instanceof_function(intern->std.ce, dom_modern_node_class_entry)) {
586586
xmlNodePtr node = (xmlNodePtr)dom_object_get_node(intern);
587-
if (node != NULL) {
587+
if (node != NULL && node->doc) {
588588
php_dom_libxml_ns_mapper *ns_mapper = NULL;
589589
if (php_dom_follow_spec_intern(intern)) {
590590
if (node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE) {

ext/dom/tests/gh14652.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-14652 segfault on object cloning
3+
--EXTENSIONS--
4+
dom
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
function varToString($var) {
10+
}
11+
$attr = new DOMAttr('category', 'books');
12+
$script1_dataflow = $attr;
13+
class test {
14+
private function __clone() {
15+
}
16+
}
17+
$clone = clone $script1_dataflow;
18+
echo "OK";
19+
--EXPECT--
20+
OK

0 commit comments

Comments
 (0)