Skip to content

Commit 7fe168d

Browse files
committed
Fix uaf in SplFixedArray::unset()
Fixes phpGH-16478 Closes phpGH-16481
1 parent 12c987f commit 7fe168d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ PHP NEWS
7171
. Fixed bug GH-16464 (Use-after-free in SplDoublyLinkedList::offsetSet()).
7272
(ilutov)
7373
. Fixed bug GH-16479 (Use-after-free in SplObjectStorage::setInfo()). (ilutov)
74+
. Fixed bug GH-16478 (Use-after-free in SplFixedArray::unset()). (ilutov)
7475

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

ext/spl/spl_fixedarray.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,10 @@ static void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *
484484
return;
485485
} else {
486486
intern->array.should_rebuild_properties = true;
487-
zval_ptr_dtor(&(intern->array.elements[index]));
487+
zval garbage;
488+
ZVAL_COPY_VALUE(&garbage, &intern->array.elements[index]);
488489
ZVAL_NULL(&intern->array.elements[index]);
490+
zval_ptr_dtor(&garbage);
489491
}
490492
}
491493

ext/spl/tests/gh16478.phpt

+21
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)