Skip to content

Commit 8e8e001

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix trampoline leak on dynamic static call of non-static method
2 parents b3f4a31 + ab98944 commit 8e8e001

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Dynamic static call of non-static method
3+
--FILE--
4+
<?php
5+
class Foo {
6+
function test1() {
7+
$method = ['Foo', 'bar'];
8+
$method();
9+
}
10+
function test2() {
11+
$method = 'Foo::bar';
12+
$method();
13+
}
14+
function __call($name, $args) {}
15+
}
16+
$x = new Foo;
17+
try {
18+
$x->test1();
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
try {
23+
$x->test2();
24+
} catch (Error $e) {
25+
echo $e->getMessage(), "\n";
26+
}
27+
?>
28+
--EXPECT--
29+
Non-static method Foo::bar() cannot be called statically
30+
Non-static method Foo::bar() cannot be called statically

Zend/zend_execute.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,10 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
40214021

40224022
if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) {
40234023
zend_non_static_method_call(fbc);
4024+
if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
4025+
zend_string_release_ex(fbc->common.function_name, 0);
4026+
zend_free_trampoline(fbc);
4027+
}
40244028
return NULL;
40254029
}
40264030
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
@@ -4145,6 +4149,10 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_ar
41454149
}
41464150
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
41474151
zend_non_static_method_call(fbc);
4152+
if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
4153+
zend_string_release_ex(fbc->common.function_name, 0);
4154+
zend_free_trampoline(fbc);
4155+
}
41484156
return NULL;
41494157
}
41504158
object_or_called_scope = called_scope;

0 commit comments

Comments
 (0)