Skip to content

Commit 9ebe849

Browse files
committed
Don't replace tmp with cv in YIELD argument
For by-ref generators, these may have different behavior. Fixes oss-fuzz 6059739298004992.
1 parent 845a67f commit 9ebe849

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Make sure optimization does not interfere with yield by ref
3+
--FILE--
4+
<?php
5+
6+
function &gen() {
7+
yield $v = 0;
8+
yield $v = 1;
9+
}
10+
11+
foreach (gen() as $v) {
12+
var_dump($v);
13+
}
14+
15+
?>
16+
--EXPECTF--
17+
Notice: Only variable references should be yielded by reference in %s on line %d
18+
int(0)
19+
20+
Notice: Only variable references should be yielded by reference in %s on line %d
21+
int(1)

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,8 @@ static int zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ssa
10101010
&& op_array->opcodes[use].opcode != ZEND_FREE
10111011
&& op_array->opcodes[use].opcode != ZEND_SEND_VAL
10121012
&& op_array->opcodes[use].opcode != ZEND_SEND_VAL_EX
1013-
&& op_array->opcodes[use].opcode != ZEND_VERIFY_RETURN_TYPE) {
1013+
&& op_array->opcodes[use].opcode != ZEND_VERIFY_RETURN_TYPE
1014+
&& op_array->opcodes[use].opcode != ZEND_YIELD) {
10141015
if (use > def) {
10151016
int i = use;
10161017
const zend_op *opline = &op_array->opcodes[use];

0 commit comments

Comments
 (0)