Skip to content

Commit

Permalink
Fix GH-14652: segfault on node without document. (#14653)
Browse files Browse the repository at this point in the history
do not bother trying to clone the inner document if there is none to
begin with.
  • Loading branch information
devnexen authored Jun 24, 2024
1 parent 835cb69 commit 5c55306
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions ext/dom/tests/gh14652.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-14652 segfault on object cloning
--EXTENSIONS--
dom
--CREDITS--
YuanchengJiang
--FILE--
<?php
$attr = new DOMAttr('category', 'books');
$clone = clone $attr;
$attr->value = "hello";

var_dump($attr->value);
var_dump($clone->value);
?>
--EXPECT--
string(5) "hello"
string(5) "books"

0 comments on commit 5c55306

Please sign in to comment.