Skip to content

Commit 0932b76

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix uaf in SplFixedArray::unset()
2 parents 40e43ff + 7fe168d commit 0932b76

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ PHP NEWS
7777
. Fixed bug GH-16464 (Use-after-free in SplDoublyLinkedList::offsetSet()).
7878
(ilutov)
7979
. Fixed bug GH-16479 (Use-after-free in SplObjectStorage::setInfo()). (ilutov)
80+
. Fixed bug GH-16478 (Use-after-free in SplFixedArray::unset()). (ilutov)
8081

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

ext/spl/spl_fixedarray.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,10 @@ static void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *
470470
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
471471
return;
472472
} else {
473-
zval_ptr_dtor(&(intern->array.elements[index]));
473+
zval garbage;
474+
ZVAL_COPY_VALUE(&garbage, &intern->array.elements[index]);
474475
ZVAL_NULL(&intern->array.elements[index]);
476+
zval_ptr_dtor(&garbage);
475477
}
476478
}
477479

ext/spl/tests/gh16478.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-16478: Use-after-free in SplFixedArray::unset()
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
function __destruct() {
8+
global $arr;
9+
$arr->setSize(0);
10+
}
11+
}
12+
13+
$arr = new SplFixedArray(2);
14+
$arr[0] = new C;
15+
unset($arr[0]);
16+
var_dump($arr);
17+
18+
?>
19+
--EXPECT--
20+
object(SplFixedArray)#1 (0) {
21+
}

0 commit comments

Comments
 (0)