Skip to content

Commit 66ed949

Browse files
committed
Test showing the issue
1 parent ed2c6ba commit 66ed949

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

ext/dom/tests/bug22077.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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/>"

0 commit comments

Comments
 (0)