Skip to content

Commit 584a7b8

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix phpGH-13931: Applying zero offset to null pointer in Zend/zend_opcode.c
2 parents c2456e9 + 550e0ce commit 584a7b8

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Zend/tests/gh13931.phpt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-13931 (Applying zero offset to null pointer in Zend/zend_opcode.c)
3+
--FILE--
4+
<?php
5+
6+
register_shutdown_function(function() {
7+
var_dump(eval("return 1+3;"));
8+
});
9+
10+
eval(<<<EVAL
11+
function foo () {
12+
try {
13+
break;
14+
} finally {
15+
}
16+
}
17+
foo();
18+
EVAL);
19+
20+
?>
21+
--EXPECTF--
22+
Fatal error: 'break' not in the 'loop' or 'switch' context in %s on line %d
23+
int(4)

main/main.c

+8
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,14 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
14131413
/* restore memory limit */
14141414
zend_set_memory_limit(PG(memory_limit));
14151415
zend_objects_store_mark_destructed(&EG(objects_store));
1416+
if (CG(in_compilation) && (type == E_COMPILE_ERROR || type == E_PARSE)) {
1417+
/* We bailout during compilation which may for example leave stale entries in CG(loop_var_stack).
1418+
* If code is compiled during shutdown, we need to make sure the compiler is reset to a clean state,
1419+
* otherwise this will lead to incorrect compilation during shutdown.
1420+
* We don't do a full re-initialization via init_compiler() because that will also reset streams and resources. */
1421+
shutdown_compiler();
1422+
zend_init_compiler_data_structures();
1423+
}
14161424
zend_bailout();
14171425
return;
14181426
}

sapi/phpdbg/tests/gh13931.phpt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Applying zero offset to null pointer in Zend/zend_opcode.c
3+
--FILE--
4+
<?php
5+
function foo () {
6+
try {
7+
break;
8+
} finally {
9+
}
10+
}
11+
foo();
12+
?>
13+
--PHPDBG--
14+
ev 1 + 3
15+
ev 2 ** 3
16+
q
17+
--EXPECTF--
18+
Fatal error: 'break' not in the 'loop' or 'switch' context in %s on line %d
19+
prompt> 4
20+
prompt> 8
21+
prompt>

0 commit comments

Comments
 (0)