Skip to content

dom: clear the xpath callback registrations before freeing them - #306

Closed
iliaal wants to merge 1 commit into
PHP-8.4from
fix/dom-xpath-callbacks-dtor-reentrancy
Closed

dom: clear the xpath callback registrations before freeing them#306
iliaal wants to merge 1 commit into
PHP-8.4from
fix/dom-xpath-callbacks-dtor-reentrancy

Conversation

@iliaal

@iliaal iliaal commented Sep 8, 2026

Copy link
Copy Markdown
Owner

php_dom_xpath_callbacks_dtor() freed php_ns and each namespaces entry but left registry->php_ns and registry->namespaces pointing at the freed memory, and it then destroyed node_list, which runs node destructors. A destructor that calls gc_collect_cycles() reaches php_dom_xpath_callback_ns_get_gc() through those still-set fields and iterates freed memory.

Reachable from userland by calling DOMXPath::__construct() a second time on an object that already has php:function registrations and a populated node list, which is the path at ext/dom/xpath.c that tears the registry down on a live object.

php_dom_xpath_callbacks_dtor() freed php_ns and each namespaces entry while
leaving registry->php_ns and registry->namespaces pointing at them, and it
then destroyed node_list, which runs node destructors. A destructor calling
gc_collect_cycles() therefore reached php_dom_xpath_callback_ns_get_gc()
through the still-set fields and iterated freed memory. Reachable from
userland by calling DOMXPath::__construct() a second time on an object that
has php:function registrations and a populated node list.

Closes phpGH-23621
@iliaal
iliaal force-pushed the fix/dom-xpath-callbacks-dtor-reentrancy branch from 2518794 to 354146d Compare September 8, 2026 18:42
@iliaal

iliaal commented Sep 8, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream as php#23621.

@iliaal iliaal closed this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant