Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ PHP NEWS
. Fixed a tracing JIT crash when compiling a side trace for a method of a
class that could not be stored in the inheritance cache. (GH-21710)
(Arnaud, iliaal)
. Fixed a call_stack buffer overflow in zend_analyze_calls() when dead code
elimination has removed the DO_FCALL opcodes. (Mrmaxmeier)

- PDO:
. Fixed a leak when a persistent connection failed a liveness check
Expand Down
5 changes: 4 additions & 1 deletion Zend/Optimizer/zend_call_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ ZEND_API void zend_analyze_calls(zend_arena **arena, zend_script *script, uint32
ALLOCA_FLAG(use_heap);
bool is_prototype;

call_stack = do_alloca((op_array->last / 2) * sizeof(zend_call_info*), use_heap);
// Note: Reserve one call stack slot per operation. Each opcode pushes at
// most one entry to the call stack, and (with dead code elimination) it's
// possible to never pop from the stack.
call_stack = do_alloca(op_array->last * sizeof(zend_call_info*), use_heap);
call_info = NULL;
while (opline != end) {
switch (opline->opcode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
zend_analyze_calls(): call_stack overflow when dead code elimination removed the DO_FCALLs
--EXTENSIONS--
opcache
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.jit=disable
--ENV--
USE_ZEND_ALLOC=0
USE_TRACKED_ALLOC=1
--FILE--
<?php
function test() {
new A(new B(new C(new D(match ([]) { 1 => 2 }))));
}
echo "OK\n";
?>
--EXPECT--
OK
Loading