Skip to content

Commit f40c8fd

Browse files
committed
Fix return-by-ref from array_reduce callback
Fixes oss-fuzz #32990.
1 parent a3e6735 commit f40c8fd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ext/standard/array.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,6 +5877,9 @@ PHP_FUNCTION(array_reduce)
58775877
zval_ptr_dtor(&args[1]);
58785878
zval_ptr_dtor(&args[0]);
58795879
ZVAL_COPY_VALUE(return_value, &retval);
5880+
if (UNEXPECTED(Z_ISREF_P(return_value))) {
5881+
zend_unwrap_reference(return_value);
5882+
}
58805883
} else {
58815884
zval_ptr_dtor(&args[1]);
58825885
zval_ptr_dtor(&args[0]);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Return by reference from array_reduce() callback
3+
--FILE--
4+
<?php
5+
$array = [1, 2];
6+
var_dump(array_reduce($array, function &($a, $b) {
7+
return $b;
8+
}, 0));
9+
?>
10+
--EXPECT--
11+
int(2)

0 commit comments

Comments
 (0)