Skip to content

Commit ab98944

Browse files
committed
Fix trampoline leak on dynamic static call of non-static method
Fixes oss-fuzz #30317.
1 parent ed4f90f commit ab98944

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
@@ -4005,6 +4005,10 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
40054005

40064006
if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) {
40074007
zend_non_static_method_call(fbc);
4008+
if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
4009+
zend_string_release_ex(fbc->common.function_name, 0);
4010+
zend_free_trampoline(fbc);
4011+
}
40084012
return NULL;
40094013
}
40104014
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
@@ -4129,6 +4133,10 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_ar
41294133
}
41304134
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
41314135
zend_non_static_method_call(fbc);
4136+
if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
4137+
zend_string_release_ex(fbc->common.function_name, 0);
4138+
zend_free_trampoline(fbc);
4139+
}
41324140
return NULL;
41334141
}
41344142
object_or_called_scope = called_scope;

0 commit comments

Comments
 (0)