Skip to content

Commit 5855bdc

Browse files
committed
Fix reference returned from CallbackFilterIterator::accept()
Fixes oss-fuzz #58181
1 parent 0ab51a9 commit 5855bdc

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Zend/tests/oss_fuzz_58181.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
oss-fuzz #58181: Fix unexpected reference returned from CallbackFilterIterator::accept()
3+
--FILE--
4+
<?php
5+
function test(array $data) {
6+
$iterator = new ArrayIterator($data);
7+
$iterator = new \CallbackFilterIterator($iterator, fn&() => true);
8+
$iterator->rewind();
9+
}
10+
11+
test(['a', 'b']);
12+
?>
13+
--EXPECTF--
14+
Notice: Only variable references should be returned by reference in %s on line %d

ext/spl/spl_iterators.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,8 @@ PHP_METHOD(CallbackFilterIterator, accept)
17871787

17881788
if (zend_call_function(fci, fcc) != SUCCESS || Z_ISUNDEF_P(return_value)) {
17891789
RETURN_FALSE;
1790+
} else if (Z_ISREF_P(return_value)) {
1791+
zend_unwrap_reference(return_value);
17901792
}
17911793
}
17921794
/* }}} */

0 commit comments

Comments
 (0)