Skip to content

Commit

Permalink
Fix phpGH-14652: segfault on node without document.
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 committed Jun 24, 2024
1 parent ab9a029 commit e5a5e41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ static zend_object *dom_objects_store_clone_obj(zend_object *zobject) /* {{{ */

if (instanceof_function(intern->std.ce, dom_node_class_entry) || instanceof_function(intern->std.ce, dom_modern_node_class_entry)) {
xmlNodePtr node = (xmlNodePtr)dom_object_get_node(intern);
if (node != NULL) {
if (node != NULL && node->doc) {
php_dom_libxml_ns_mapper *ns_mapper = NULL;
if (php_dom_follow_spec_intern(intern)) {
if (node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE) {
Expand Down
20 changes: 20 additions & 0 deletions ext/dom/tests/gh14652.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-14652 segfault on object cloning
--EXTENSIONS--
dom
--CREDITS--
YuanchengJiang
--FILE--
<?php
function varToString($var) {
}
$attr = new DOMAttr('category', 'books');
$script1_dataflow = $attr;
class test {
private function __clone() {
}
}
$clone = clone $script1_dataflow;
echo "OK";
--EXPECT--
OK

0 comments on commit e5a5e41

Please sign in to comment.