File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ --TEST--
2+ test for issue #22077
3+ --DESCRIPTION--
4+ Registers a custom XPath function providing nodes from a new document.
5+ Results in a heap UAF in request shutdown if these nodes are accessed further
6+ down the road without protecting their origin document from GC.
7+ Build with '-fsanitize=address' or test with 'valgrind' or '-m'.
8+ --FILE--
9+ <?php
10+ $ document = new DOMDocument ;
11+ $ xpath = new DOMXPath ($ document );
12+ $ xpath ->registerNamespace ("my " , "my.ns " );
13+ $ xpath ->registerPHPFunctionNS ('my.ns ' , 'include ' , function (): DOMElement {
14+ $ includedDocument = new DOMDocument ;
15+ $ includedDocument ->loadXML ('<root><uaf/><node/><uaf/></root> ' );
16+ return $ includedDocument ->documentElement ;
17+ });
18+ $ nodeset = $ xpath ->query ('my:include()/uaf ' );
19+ $ node = $ nodeset ->item (0 );
20+ var_dump ($ nodeset ->length );
21+ var_dump ($ node ->ownerDocument ->saveXML ($ node ));
22+ ?>
23+ --EXPECT--
24+ int(2)
25+ string(6) "<uaf/>"
You can’t perform that action at this time.
0 commit comments