Skip to content

Commit 2515e78

Browse files
committed
JIT: Fix register clobbering
Fixes oss-fuzz #41621
1 parent c4ee668 commit 2515e78

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,9 +5000,6 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
50005000

50015001
if (opcode == ZEND_MOD) {
50025002
result_reg = ZREG_RAX;
5003-
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
5004-
| mov aword T1, r0 // save
5005-
}
50065003
} else if (Z_MODE(res_addr) == IS_REG) {
50075004
if ((opline->opcode == ZEND_SL || opline->opcode == ZEND_SR)
50085005
&& opline->op2_type != IS_CONST) {
@@ -5127,6 +5124,11 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
51275124
| GET_ZVAL_LVAL result_reg, op1_addr
51285125
| LONG_MATH ZEND_BW_AND, result_reg, tmp_addr
51295126
} else {
5127+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
5128+
| mov aword T1, r0 // save
5129+
} else if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RCX) {
5130+
| mov aword T1, Ra(ZREG_RCX) // save
5131+
}
51305132
result_reg = ZREG_RDX;
51315133
if (op2_lval == -1) {
51325134
| xor Ra(result_reg), Ra(result_reg)
@@ -5142,6 +5144,8 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
51425144
}
51435145
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
51445146
| mov r0, aword T1 // restore
5147+
} else if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RCX) {
5148+
| mov Ra(ZREG_RCX), aword T1 // restore
51455149
}
51465150
}
51475151
} else {
@@ -5183,6 +5187,9 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
51835187
|.code
51845188
}
51855189

5190+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
5191+
| mov aword T1, r0 // save
5192+
}
51865193
result_reg = ZREG_RDX;
51875194
| GET_ZVAL_LVAL ZREG_RAX, op1_addr
51885195
|.if X64

ext/opcache/tests/jit/mod_005.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
JIT MOD: 005
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+
class Test{
12+
public $prop = 32;
13+
}
14+
15+
function test2($test) {
16+
$test->prop %= 3;
17+
return $test;
18+
}
19+
20+
var_dump(test2(new Test));
21+
?>
22+
--EXPECT--
23+
object(Test)#1 (1) {
24+
["prop"]=>
25+
int(2)
26+
}

0 commit comments

Comments
 (0)