Skip to content

Commit 76138d6

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix uaf in SplFixedArray::unset()
2 parents 9cb0f03 + c82cea0 commit 76138d6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: ext/spl/spl_fixedarray.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,10 @@ static void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *
459459
zend_throw_exception(spl_ce_OutOfBoundsException, "Index invalid or out of range", 0);
460460
return;
461461
} else {
462-
zval_ptr_dtor(&(intern->array.elements[index]));
462+
zval garbage;
463+
ZVAL_COPY_VALUE(&garbage, &intern->array.elements[index]);
463464
ZVAL_NULL(&intern->array.elements[index]);
465+
zval_ptr_dtor(&garbage);
464466
}
465467
}
466468

Diff for: 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)