Skip to content

Commit 1c9bfcb

Browse files
committed
Fix #78716: Function name mangling is wrong for some parameter types
We have to cater to function parameter alignment when calculating the parameter size.
1 parent 6422c95 commit 1c9bfcb

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ PHP NEWS
88
- Date:
99
. Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin)
1010

11+
- FFI:
12+
. Fixed bug #78716 (Function name mangling is wrong for some parameter
13+
types). (cmb)
14+
1115
- FPM:
1216
. Fixed bug #78599 (env_path_info underflow in fpm_main.c can lead to RCE).
1317
(CVE-2019-11043) (Jakub Zelenka)

ext/ffi/ffi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ static size_t zend_ffi_arg_size(zend_ffi_type *type) /* {{{ */
775775
size_t arg_size = 0;
776776

777777
ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) {
778-
arg_size += ZEND_FFI_TYPE(arg_type)->size;
778+
arg_size += MAX(ZEND_FFI_TYPE(arg_type)->size, sizeof(size_t));
779779
} ZEND_HASH_FOREACH_END();
780780
return arg_size;
781781
}

ext/ffi/tests/callconv.phpt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
99
--FILE--
1010
<?php
1111
$header = <<<HEADER
12-
void __cdecl cdecl_func(int arg1, double arg2);
13-
void __stdcall stdcall_func(int arg1, double arg2);
14-
void __fastcall fastcall_func(int arg1, double arg2);
12+
void __cdecl cdecl_func(int arg1, double arg2, char arg3);
13+
void __stdcall stdcall_func(int arg1, double arg2, char arg3);
14+
void __fastcall fastcall_func(int arg1, double arg2, char arg3);
1515
HEADER;
1616
$headername = __DIR__ . '/callconv.h';
1717
$dllname = __DIR__ . "/callconv_x86.dll";
1818

1919
$ffi1 = FFI::cdef($header, $dllname);
20-
$ffi1->cdecl_func(1, 2.3);
21-
$ffi1->stdcall_func(4, 5.6);
22-
$ffi1->fastcall_func(7, 8.9);
20+
$ffi1->cdecl_func(1, 2.3, 'a');
21+
$ffi1->stdcall_func(4, 5.6, 'b');
22+
$ffi1->fastcall_func(7, 8.9, 'c');
2323

2424
file_put_contents($headername, "#define FFI_LIB \"$dllname\"\n$header");
2525

2626
$ffi2 = FFI::load($headername);
27-
$ffi2->cdecl_func(2, 3.4);
28-
$ffi2->stdcall_func(5, 6.7);
29-
$ffi2->fastcall_func(8, 9.1);
27+
$ffi2->cdecl_func(2, 3.4, 'a');
28+
$ffi2->stdcall_func(5, 6.7, 'b');
29+
$ffi2->fastcall_func(8, 9.1, 'c');
3030
?>
3131
--EXPECT--
32-
cdecl: 1, 2.300000
33-
stdcall: 4, 5.600000
34-
fastcall: 7, 8.900000
35-
cdecl: 2, 3.400000
36-
stdcall: 5, 6.700000
37-
fastcall: 8, 9.100000
32+
cdecl: 1, 2.300000, a
33+
stdcall: 4, 5.600000, b
34+
fastcall: 7, 8.900000, c
35+
cdecl: 2, 3.400000, a
36+
stdcall: 5, 6.700000, b
37+
fastcall: 8, 9.100000, c
3838
--CLEAN--
3939
<?php
4040
unlink(__DIR__ . '/callconv.h');

ext/ffi/tests/callconv_x86.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)