Skip to content

Commit 330a7b6

Browse files
committed
Fixed bug #74152 (if statement says true to a null variable)
1 parent 1d4eead commit 330a7b6

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ PHP NEWS
4343
(Andrew Nester, Nikita)
4444

4545
- Opcache:
46+
. Fixed bug #74152 (if statement says true to a null variable). (Laruence)
4647
. Fixed bug #74019 (Segfault with list). (Laruence)
4748

4849
- OpenSSL:

ext/opcache/Optimizer/block_pass.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,17 @@ static void zend_rebuild_access_path(zend_cfg *cfg, zend_op_array *op_array, int
561561
convert_to_string((v)); \
562562
}
563563

564+
static int is_predecessor_smart_branch(zend_op *start, zend_op *predecessor) {
565+
do {
566+
if (predecessor == start) {
567+
return 0;
568+
}
569+
predecessor--;
570+
} while (predecessor->opcode == ZEND_NOP);
571+
572+
return zend_is_smart_branch(predecessor);
573+
}
574+
564575
static void strip_nop(zend_code_block *block, zend_op_array *op_array, zend_optimizer_ctx *ctx)
565576
{
566577
zend_op *opline = block->start_opline;
@@ -602,8 +613,7 @@ static void strip_nop(zend_code_block *block, zend_op_array *op_array, zend_opti
602613
&& ((opline + 1)->opcode == ZEND_JMPZ
603614
|| (opline + 1)->opcode == ZEND_JMPNZ)
604615
&& (opline + 1)->op1_type & (IS_CV|IS_CONST)
605-
&& opline > op_array->opcodes
606-
&& zend_is_smart_branch(opline - 1)) {
616+
&& is_predecessor_smart_branch(op_array->opcodes, opline)) {
607617
/* don't remove NOP, that splits incorrect smart branch */
608618
opline++;
609619
break;

ext/opcache/tests/bug74152.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #74152 (if statement says true to a null variable)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--SKIPIF--
8+
<?php require_once('skipif.inc'); ?>
9+
--FILE--
10+
<?php
11+
12+
$foo = 'foo';
13+
14+
$bar = null;
15+
16+
switch ($foo) {
17+
default:
18+
case 'foo':
19+
if ($bar) {
20+
echo 'true';
21+
} else {
22+
echo 'false';
23+
}
24+
}
25+
?>
26+
--EXPECT--
27+
false

0 commit comments

Comments
 (0)