Skip to content

Commit 6a691b1

Browse files
committed
Fix building of callgraph including preloaded symbols
This issue was introduced in GH-15021. When building the call graph, we can now see preloaded functions. However, building the call graph involves adding the function to the caller list of the callee, which we don't want to do for functions not coming from the script. Fixes GH-15490
1 parent 6a51062 commit 6a691b1

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Zend/Optimizer/zend_call_graph.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ ZEND_API void zend_analyze_calls(zend_arena **arena, zend_script *script, uint32
7979

8080
if (build_flags & ZEND_CALL_TREE) {
8181
call_info->next_caller = NULL;
82-
} else if (func->type == ZEND_INTERNAL_FUNCTION) {
82+
} else if (func->type == ZEND_INTERNAL_FUNCTION
83+
|| func->op_array.filename != script->filename) {
8384
call_info->next_caller = NULL;
8485
} else {
8586
zend_func_info *callee_func_info = ZEND_FUNC_INFO(&func->op_array);

ext/opcache/tests/jit/gh15490.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
function foo() {
4+
bar();
5+
}
6+
7+
function bar() {
8+
echo 'Hello world!';
9+
}

ext/opcache/tests/jit/gh15490.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-15490: use-after-free when traversing call graph
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.file_update_protection=0
9+
opcache.preload={PWD}/gh15490.inc
10+
opcache.jit=1235
11+
--SKIPIF--
12+
<?php
13+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
14+
?>
15+
--FILE--
16+
<?php
17+
foo();
18+
?>
19+
--EXPECT--
20+
Hello world!

0 commit comments

Comments
 (0)