Skip to content

Commit 1fff0c0

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17224: UAF in importNode
2 parents afc1f0d + 62dc89d commit 1fff0c0

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

ext/dom/document.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,14 +783,14 @@ PHP_METHOD(DOMDocument, importNode)
783783
xmlNsPtr nsptr = NULL;
784784
xmlNodePtr root = xmlDocGetRootElement(docp);
785785

786-
nsptr = xmlSearchNsByHref (nodep->doc, root, nodep->ns->href);
786+
nsptr = xmlSearchNsByHref (docp, root, nodep->ns->href);
787787
if (nsptr == NULL || nsptr->prefix == NULL) {
788788
int errorcode;
789789
nsptr = dom_get_ns(root, (char *) nodep->ns->href, &errorcode, (char *) nodep->ns->prefix);
790790

791791
/* If there is no root, the namespace cannot be attached to it, so we have to attach it to the old list. */
792792
if (nsptr != NULL && root == NULL) {
793-
php_libxml_set_old_ns(nodep->doc, nsptr);
793+
php_libxml_set_old_ns(docp, nsptr);
794794
}
795795
}
796796
retnodep->ns = nsptr;

ext/dom/tests/gh17224.phpt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
--TEST--
2+
GH-17224 (UAF in importNode)
3+
--EXTENSIONS--
4+
dom
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
$aDOM = new DOMDocument();
10+
$fromdom = new DOMDocument();
11+
$fromdom->loadXML('<data xmlns:ai="http://test.org" ai:attr="namespaced" />');
12+
$attr = $fromdom->firstChild->attributes->item(0);
13+
$att = $aDOM->importNode($attr);
14+
$doc = new DOMDocument;
15+
$fromdom->load(__DIR__."/book.xml");
16+
unset($attr);
17+
var_dump($att);
18+
?>
19+
--EXPECTF--
20+
object(DOMAttr)#%d (%d) {
21+
["specified"]=>
22+
bool(true)
23+
["schemaTypeInfo"]=>
24+
NULL
25+
["name"]=>
26+
string(4) "attr"
27+
["value"]=>
28+
string(10) "namespaced"
29+
["ownerElement"]=>
30+
NULL
31+
["nodeName"]=>
32+
string(7) "ai:attr"
33+
["nodeValue"]=>
34+
string(10) "namespaced"
35+
["nodeType"]=>
36+
int(2)
37+
["parentNode"]=>
38+
NULL
39+
["parentElement"]=>
40+
NULL
41+
["childNodes"]=>
42+
string(22) "(object value omitted)"
43+
["firstChild"]=>
44+
string(22) "(object value omitted)"
45+
["lastChild"]=>
46+
string(22) "(object value omitted)"
47+
["previousSibling"]=>
48+
NULL
49+
["nextSibling"]=>
50+
NULL
51+
["attributes"]=>
52+
NULL
53+
["isConnected"]=>
54+
bool(false)
55+
["ownerDocument"]=>
56+
string(22) "(object value omitted)"
57+
["namespaceURI"]=>
58+
string(15) "http://test.org"
59+
["prefix"]=>
60+
string(2) "ai"
61+
["localName"]=>
62+
string(4) "attr"
63+
["baseURI"]=>
64+
NULL
65+
["textContent"]=>
66+
string(10) "namespaced"
67+
}

0 commit comments

Comments
 (0)