Skip to content

Commit 95e0cc0

Browse files
committed
Fix missing undef checks for comparisons
1 parent 0e0f50b commit 95e0cc0

File tree

2 files changed

+69
-12
lines changed

2 files changed

+69
-12
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7697,19 +7697,19 @@ static int zend_jit_cmp(dasm_State **Dst,
76977697
(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))));
76987698

76997699
if ((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG)) {
7700-
if (op1_info & (MAY_BE_ANY-MAY_BE_LONG)) {
7700+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) {
77017701
if (op1_info & MAY_BE_DOUBLE) {
77027702
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >4
77037703
} else {
77047704
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >9
77057705
}
77067706
}
7707-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_LONG))) {
7707+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG))) {
77087708
if (op2_info & MAY_BE_DOUBLE) {
77097709
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >3
77107710
|.cold_code
77117711
|3:
7712-
if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7712+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
77137713
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >9
77147714
}
77157715
if (!zend_jit_cmp_long_double(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7727,11 +7727,11 @@ static int zend_jit_cmp(dasm_State **Dst,
77277727
if (op1_info & MAY_BE_DOUBLE) {
77287728
|.cold_code
77297729
|4:
7730-
if (op1_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7730+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
77317731
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >9
77327732
}
77337733
if (op2_info & MAY_BE_DOUBLE) {
7734-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7734+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
77357735
if (!same_ops) {
77367736
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >5
77377737
} else {
@@ -7745,7 +7745,7 @@ static int zend_jit_cmp(dasm_State **Dst,
77457745
}
77467746
if (!same_ops) {
77477747
|5:
7748-
if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7748+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
77497749
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >9
77507750
}
77517751
if (!zend_jit_cmp_double_long(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7758,11 +7758,11 @@ static int zend_jit_cmp(dasm_State **Dst,
77587758
} else if ((op1_info & MAY_BE_DOUBLE) &&
77597759
!(op1_info & MAY_BE_LONG) &&
77607760
(op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) {
7761-
if (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) {
7761+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) {
77627762
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >9
77637763
}
77647764
if (op2_info & MAY_BE_DOUBLE) {
7765-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7765+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
77667766
if (!same_ops && (op2_info & MAY_BE_LONG)) {
77677767
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >3
77687768
} else {
@@ -7778,7 +7778,7 @@ static int zend_jit_cmp(dasm_State **Dst,
77787778
|.cold_code
77797779
}
77807780
|3:
7781-
if (op2_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
7781+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
77827782
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >9
77837783
}
77847784
if (!zend_jit_cmp_double_long(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7792,11 +7792,11 @@ static int zend_jit_cmp(dasm_State **Dst,
77927792
} else if ((op2_info & MAY_BE_DOUBLE) &&
77937793
!(op2_info & MAY_BE_LONG) &&
77947794
(op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) {
7795-
if (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) {
7795+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) {
77967796
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >9
77977797
}
77987798
if (op1_info & MAY_BE_DOUBLE) {
7799-
if (!same_ops && (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7799+
if (!same_ops && (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
78007800
if (!same_ops && (op1_info & MAY_BE_LONG)) {
78017801
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >3
78027802
} else {
@@ -7812,7 +7812,7 @@ static int zend_jit_cmp(dasm_State **Dst,
78127812
|.cold_code
78137813
}
78147814
|3:
7815-
if (op1_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
7815+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
78167816
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >9
78177817
}
78187818
if (!zend_jit_cmp_long_double(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {

ext/opcache/tests/jit/cmp_006.phpt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
JIT CMP: 006 Undefined variable checks
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
--FILE--
10+
<?php
11+
function test1($c) {
12+
if ($c) {
13+
$x = 1;
14+
}
15+
var_dump($x == 1);
16+
}
17+
function test2($c) {
18+
if ($c) {
19+
$x = 1.0;
20+
}
21+
var_dump($x == 1.0);
22+
}
23+
function test3($c) {
24+
if (!$c) {
25+
$x = 1;
26+
}
27+
if ($c) {
28+
$y = 1;
29+
}
30+
var_dump($x == $y);
31+
}
32+
function test4($c) {
33+
if (!$c) {
34+
$x = 1.0;
35+
}
36+
if ($c) {
37+
$y = 1.0;
38+
}
39+
var_dump($x == $y);
40+
}
41+
test1(false);
42+
test2(false);
43+
test3(false);
44+
test4(false);
45+
?>
46+
--EXPECTF--
47+
Warning: Undefined variable $x in %s on line %d
48+
bool(false)
49+
50+
Warning: Undefined variable $x in %s on line %d
51+
bool(false)
52+
53+
Warning: Undefined variable $y in %s on line %d
54+
bool(false)
55+
56+
Warning: Undefined variable $y in %s on line %d
57+
bool(false)

0 commit comments

Comments
 (0)