Skip to content

Commit 017062f

Browse files
committed
Reset user func trampoline values FFI may overwrite
1 parent 94d6bcb commit 017062f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Zend/zend_object_handlers.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,13 @@ ZEND_API zend_function *zend_get_call_trampoline_func(zend_class_entry *ce, zend
12711271
func->required_num_args = 0;
12721272
func->arg_info = (zend_arg_info *) arg_info;
12731273

1274+
// These maybe overwritten by FFI zend_ffi_cdata_get_closure()
1275+
// (handler, module, reserved[0], reserved[1])
1276+
func->cache_size = 0;
1277+
func->last_var = 0;
1278+
func->last = 0;
1279+
ZEND_MAP_PTR(func->static_variables_ptr) = NULL;
1280+
12741281
return (zend_function*)func;
12751282
}
12761283
/* }}} */

ext/ffi/tests/trampoline_reset.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Test
3+
--EXTENSIONS--
4+
ffi
5+
--SKIPIF--
6+
<?php
7+
try {
8+
$libc = FFI::cdef("int printf(const char *format, ...);", "libc.so.6");
9+
} catch (Throwable $_) {
10+
die('skip libc.so.6 not available');
11+
}
12+
?>
13+
--INI--
14+
ffi.enable=1
15+
--FILE--
16+
<?php
17+
class Test
18+
{
19+
public static function __callStatic($name, $args)
20+
{
21+
echo "$name called\n";
22+
}
23+
}
24+
25+
Test::works1();
26+
Test::works2();
27+
28+
$ffi = FFI::cdef('int printf(const char *format, ...);', 'libc.so.6');
29+
$ffi->printf("Hello %s!\n", "world");
30+
31+
Test::breaks();
32+
?>
33+
--EXPECT--
34+
works1 called
35+
works2 called
36+
breaks called
37+
Hello world!

0 commit comments

Comments
 (0)