Skip to content

Commit 483bb87

Browse files
committed
Fix building of callgraph including preloaded symbols
This issue was introduced in phpGH-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 phpGH-15490
1 parent b9b317a commit 483bb87

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ PHP NEWS
3434
. Fixed bug GH-15432 (Heap corruption when querying a vector). (cmb,
3535
Kamil Tekiela)
3636

37+
- Opcache:
38+
. Fixed bug GH-15490 (Building of callgraph modifies preloaded symbols).
39+
(ilutov)
40+
3741
- PDO_MYSQL:
3842
. mysqlnd: support ER_CLIENT_INTERACTION_TIMEOUT. (Appla)
3943

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)