Skip to content

Commit 40e43ff

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix use-after-free in SplObjectStorage::setInfo()
2 parents 5dba6ae + 12c987f commit 40e43ff

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ PHP NEWS
7676
. Fixed bug GH-16337 (Use-after-free in SplHeap). (nielsdos)
7777
. Fixed bug GH-16464 (Use-after-free in SplDoublyLinkedList::offsetSet()).
7878
(ilutov)
79+
. Fixed bug GH-16479 (Use-after-free in SplObjectStorage::setInfo()). (ilutov)
7980

8081
- Standard:
8182
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with

ext/spl/spl_observer.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,10 @@ PHP_METHOD(SplObjectStorage, setInfo)
744744
if ((element = zend_hash_get_current_data_ptr_ex(&intern->storage, &intern->pos)) == NULL) {
745745
RETURN_NULL();
746746
}
747-
zval_ptr_dtor(&element->inf);
747+
zval garbage;
748+
ZVAL_COPY_VALUE(&garbage, &element->inf);
748749
ZVAL_COPY(&element->inf, inf);
750+
zval_ptr_dtor(&garbage);
749751
} /* }}} */
750752

751753
/* {{{ Moves position forward */

ext/spl/tests/gh16479.phpt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-16479: Use-after-free in SplObjectStorage::setInfo()
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
function __destruct() {
8+
global $store;
9+
$store->removeAll($store);
10+
}
11+
}
12+
13+
$o = new stdClass;
14+
$store = new SplObjectStorage;
15+
$store[$o] = new C;
16+
$store->setInfo(1);
17+
var_dump($store);
18+
19+
?>
20+
--EXPECT--
21+
object(SplObjectStorage)#2 (1) {
22+
["storage":"SplObjectStorage":private]=>
23+
array(0) {
24+
}
25+
}

0 commit comments

Comments
 (0)