-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GH-14652: segfault on node without document. #14653
Conversation
ab7278b
to
e5a5e41
Compare
ext/dom/php_dom.c
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch isn't right unfortunately.
This will break the following code: https://3v4l.org/dq0ct
This could've been revealed if your test was more elaborate, when dealing with things like this I recommend also dumping some state of the objects to see if this has consequences.
The right way to fix this is by adding a null check (ns_mapper != NULL
) around the assignment of clone->document->private_data
. The reason being that:
clone->document
will be NULL for documentless nodes, and for old DOM setting this is pointless anyway- only new DOM uses the ns_mapper, and it will always have an internal document reference set (the fact that your
->document
or->doc
pointer can be NULL in old DOM is imo a design mistake that I got rid of in new DOM).
ext/dom/tests/gh14652.phpt
Outdated
} | ||
} | ||
$clone = clone $script1_dataflow; | ||
echo "OK"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure to close tests with ?>
so that phpt files can be run directly.
I think it'd be good to just copy the test code from the 3v4l link, as that code is cleaner + tests the object state. |
do not bother trying to clone the inner document if there is none to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
do not bother trying to clone the inner document if there is none to begin with.