Skip to content

Commit 9cb0f03

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix use-after-free in SplObjectStorage::setInfo()
2 parents 84d6cb8 + 6d6b20f commit 9cb0f03

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/spl/spl_observer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,10 @@ PHP_METHOD(SplObjectStorage, setInfo)
739739
if ((element = zend_hash_get_current_data_ptr_ex(&intern->storage, &intern->pos)) == NULL) {
740740
RETURN_NULL();
741741
}
742-
zval_ptr_dtor(&element->inf);
742+
zval garbage;
743+
ZVAL_COPY_VALUE(&garbage, &element->inf);
743744
ZVAL_COPY(&element->inf, inf);
745+
zval_ptr_dtor(&garbage);
744746
} /* }}} */
745747

746748
/* {{{ Moves position forward */

ext/spl/tests/gh16479.phpt

Lines changed: 25 additions & 0 deletions
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)