Skip to content

Commit fcff846

Browse files
iluuu1994arnaud-lb
andauthored
Fix borked FETCH_W+ZEND_FETCH_GLOBAL_LOCK optimization (GH-21121)
Fixes OSS-Fuzz #481014628 Introduced in GH-20628 Co-authored-by: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com>
1 parent e1b2f1f commit fcff846

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
176176
&& zend_optimizer_update_op1_const(op_array, opline, &c)) {
177177
VAR_SOURCE(op1) = NULL;
178178
if (opline->opcode != ZEND_JMP_NULL
179-
&& !zend_bitset_in(used_ext, VAR_NUM(src->result.var))) {
179+
&& !zend_bitset_in(used_ext, VAR_NUM(src->result.var))
180+
/* FETCH_W with ZEND_FETCH_GLOBAL_LOCK does not free op1, which will be used again. */
181+
&& !(opline->opcode == ZEND_FETCH_W && (opline->extended_value & ZEND_FETCH_GLOBAL_LOCK))) {
180182
literal_dtor(&ZEND_OP1_LITERAL(src));
181183
MAKE_NOP(src);
182184
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
OSS-Fuzz #481014628: Borked FETCH_W+ZEND_FETCH_GLOBAL_LOCK optimization
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
--FILE--
9+
<?php
10+
11+
function f() {
12+
return 'foo';
13+
}
14+
15+
function test() {
16+
global ${f()};
17+
var_dump($foo);
18+
}
19+
20+
test();
21+
$foo = 42;
22+
test();
23+
24+
?>
25+
--EXPECT--
26+
NULL
27+
int(42)

0 commit comments

Comments
 (0)