Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f576b81

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-16906: Reloading document can cause UAF in iterator
2 parents cd977ae + 52c7c74 commit f576b81

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

‎ext/dom/php_dom.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,10 @@ void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xml
14651465
mapptr->baseobj = basenode;
14661466
mapptr->nodetype = ntype;
14671467
mapptr->ht = ht;
1468+
if (EXPECTED(doc != NULL)) {
1469+
mapptr->dict = doc->dict;
1470+
xmlDictReference(doc->dict);
1471+
}
14681472

14691473
const xmlChar* tmp;
14701474

@@ -1578,6 +1582,7 @@ void dom_nnodemap_objects_free_storage(zend_object *object) /* {{{ */
15781582
if (!Z_ISUNDEF(objmap->baseobj_zv)) {
15791583
zval_ptr_dtor(&objmap->baseobj_zv);
15801584
}
1585+
xmlDictFree(objmap->dict);
15811586
efree(objmap);
15821587
intern->ptr = NULL;
15831588
}
@@ -1609,6 +1614,7 @@ zend_object *dom_nnodemap_objects_new(zend_class_entry *class_type)
16091614
objmap->cached_length = -1;
16101615
objmap->cached_obj = NULL;
16111616
objmap->cached_obj_index = 0;
1617+
objmap->dict = NULL;
16121618

16131619
return &intern->std;
16141620
}

‎ext/dom/php_dom.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef struct dom_nnodemap_object {
8888
php_libxml_cache_tag cache_tag;
8989
dom_object *cached_obj;
9090
zend_long cached_obj_index;
91+
xmlDictPtr dict;
9192
bool free_local : 1;
9293
bool free_ns : 1;
9394
} dom_nnodemap_object;

‎ext/dom/tests/gh16906.phpt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-16906 (Reloading document can cause UAF in iterator)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument;
8+
$doc->loadXML('<?xml version="1.0"?><span><strong id="1"/><strong id="2"/></span>');
9+
$list = $doc->getElementsByTagName('strong');
10+
$doc->load(__DIR__."/book.xml");
11+
var_dump($list);
12+
?>
13+
--EXPECT--
14+
object(DOMNodeList)#2 (1) {
15+
["length"]=>
16+
int(0)
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /