[php-src] PR #24570: ext/dom: fix use-after-free with XPath callback returning foreign-doc…
| From: | devnexen | Date: | Thu, 22 Oct 2026 19:05:16 +0000 |
| Subject: | [php-src] PR #24570: ext/dom: fix use-after-free with XPath callback returning foreign-doc… | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-39734@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/24570
Author: devnexen
…ument node.
Fix GH-22554
A PHP XPath callback that returns a node belonging to a document created inside the callback (e.g.
$d->documentElement of a throwaway DOMDocument) parks that node in the DOMXPath node_list to keep
it alive. When a sibling callback consumes a node navigated into that foreign document, the proxy
object was created with the DOMXPath's own dom as parent, so it took a reference on the wrong
document and none on the foreign one. On teardown the foreign document could be freed while the
proxy still referenced it.
Route the proxy factory through dom_xpath_intern_for_doc() so the created object shares the ref_obj
of the node's actual document, mirroring the query-result path.
close GH-22562
(cherry picked from commit f36660d64507e0d5d9fce73739031faac8139ded)