Skip to content

Commit 0d44bbd

Browse files
committed
JIT: Fixed incorrect code generation
Fixes oss-fuzz #46328
1 parent 1364945 commit 0d44bbd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14186,6 +14186,7 @@ static int zend_jit_assign_obj(dasm_State **Dst,
1418614186
zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This));
1418714187
zend_jit_addr prop_addr;
1418814188
zend_bool needs_slow_path = 0;
14189+
zend_bool needs_val_dtor = 0;
1418914190

1419014191
if (RETURN_VALUE_USED(opline)) {
1419114192
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var);
@@ -14242,6 +14243,7 @@ static int zend_jit_assign_obj(dasm_State **Dst,
1424214243
}
1424314244
if (((opline+1)->op1_type & (IS_VAR|IS_TMP_VAR))
1424414245
&& (val_info & (MAY_BE_REF|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) {
14246+
needs_val_dtor = 1;
1424514247
| jmp >7
1424614248
} else {
1424714249
| jmp >9
@@ -14459,6 +14461,13 @@ static int zend_jit_assign_obj(dasm_State **Dst,
1445914461
val_info |= MAY_BE_RC1|MAY_BE_RCN;
1446014462
}
1446114463

14464+
|7:
14465+
| // FREE_OP_DATA();
14466+
| FREE_OP (opline+1)->op1_type, (opline+1)->op1, val_info, 0, opline
14467+
| jmp >9
14468+
|.code
14469+
} else if (needs_val_dtor) {
14470+
|.cold_code
1446214471
|7:
1446314472
| // FREE_OP_DATA();
1446414473
| FREE_OP (opline+1)->op1_type, (opline+1)->op1, val_info, 0, opline
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
JIT ASSIGN_OBJ: Assign undefined vatiable to property
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
class Node {
11+
public $previous;
12+
public $next;
13+
}
14+
15+
function xxx() {
16+
$firstNode = new Node();
17+
// $firstNode->previous = $firstNode;
18+
$firstNode->next = $firstNode;
19+
$circularDoublyLinkedList = null;
20+
for ($i = 0; $i < 2; $i++) {
21+
$currentNode = $circularDoublyLinkedList;
22+
$nextNode = $circularDoublyLinkedList->next;
23+
$newNode->next = $undef1->next; // <- ???
24+
$newNode = new Node();
25+
$currentNode->undef2 = new Node();
26+
$circularDoublyLinkedList = $nextNode;
27+
}
28+
}
29+
30+
try {
31+
@xxx();
32+
} catch (Throwable $e) {
33+
echo "Exception: " . $e->getMessage() . "\n";
34+
}
35+
?>
36+
--EXPECT--
37+
Exception: Attempt to assign property "next" on null

0 commit comments

Comments
 (0)