Skip to content

Commit 3ffb310

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Use-after-free in extract() with EXTR_REFS
2 parents 93826d9 + a21065e commit 3ffb310

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
. Fixed bug GH-17711 and GH-18022 (Infinite recursion on deprecated attribute
77
evaluation). (ilutov)
88
. Fixed bug GH-18038 (Lazy proxy calls magic methods twice). (Arnaud)
9+
. Fixed bug GH-18209 (Use-after-free in extract() with EXTR_REFS). (ilutov)
910

1011
- GD:
1112
. Fixed imagecrop() overflow with rect argument with x/width y/heigh usage

ext/standard/array.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,8 +1972,10 @@ static zend_long php_extract_ref_overwrite(zend_array *arr, zend_array *symbol_t
19721972
} else {
19731973
ZVAL_MAKE_REF_EX(entry, 2);
19741974
}
1975-
zval_ptr_dtor(orig_var);
1975+
zval garbage;
1976+
ZVAL_COPY_VALUE(&garbage, orig_var);
19761977
ZVAL_REF(orig_var, Z_REF_P(entry));
1978+
zval_ptr_dtor(&garbage);
19771979
} else {
19781980
if (Z_ISREF_P(entry)) {
19791981
Z_ADDREF_P(entry);

ext/standard/tests/gh18209.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-18209: Use-after-free in extract() with EXTR_REFS
3+
--CREDITS--
4+
Noam Rathaus (nrathaus)
5+
--FILE--
6+
<?php
7+
8+
class C {
9+
public function __destruct() {
10+
var_dump($GLOBALS['b']);
11+
$GLOBALS['b'] = 43;
12+
}
13+
}
14+
15+
$b = new C;
16+
$array = ['b' => 42];
17+
extract($array, EXTR_REFS);
18+
var_dump($b);
19+
20+
?>
21+
--EXPECT--
22+
int(42)
23+
int(43)

0 commit comments

Comments
 (0)