]> granicus.if.org Git - php/commitdiff
Fix #78716: Function name mangling is wrong for some parameter types
authorChristoph M. Becker <cmbecker69@gmx.de>
Tue, 22 Oct 2019 09:33:00 +0000 (11:33 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 22 Oct 2019 09:38:58 +0000 (11:38 +0200)
We have to cater to function parameter alignment when calculating the
parameter size.

NEWS
ext/ffi/ffi.c
ext/ffi/tests/callconv.phpt
ext/ffi/tests/callconv_x86.dll

diff --git a/NEWS b/NEWS
index a192b92ea46f0bbd774def30ee6b6297c5c096f9..5003143e92b21919c452ea16a7a4e047e4bdb8e8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@ PHP                                                                        NEWS
 - Date:
   . Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin)
 
+- FFI:
+  . Fixed bug #78716 (Function name mangling is wrong for some parameter 
+    types). (cmb)
+
 - FPM:
   . Fixed bug #78599 (env_path_info underflow in fpm_main.c can lead to RCE).
     (CVE-2019-11043) (Jakub Zelenka)
index 1d6f84b6b2234c60fac5582d2dcf6fa7ab401676..1edba157a171cb33b75d8eeb4f84d26b6fead4ab 100644 (file)
@@ -775,7 +775,7 @@ static size_t zend_ffi_arg_size(zend_ffi_type *type) /* {{{ */
        size_t arg_size = 0;
 
        ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) {
-               arg_size += ZEND_FFI_TYPE(arg_type)->size;
+               arg_size += MAX(ZEND_FFI_TYPE(arg_type)->size, sizeof(size_t));
        } ZEND_HASH_FOREACH_END();
        return arg_size;
 }
index aa481de2249cc14c137c263f207206fb6946a554..233c73f110101abdca2c4868de961fb4016e4bde 100644 (file)
@@ -9,32 +9,32 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
 --FILE--
 <?php
 $header = <<<HEADER
-void __cdecl cdecl_func(int arg1, double arg2);
-void __stdcall stdcall_func(int arg1, double arg2);
-void __fastcall fastcall_func(int arg1, double arg2);
+void __cdecl cdecl_func(int arg1, double arg2, char arg3);
+void __stdcall stdcall_func(int arg1, double arg2, char arg3);
+void __fastcall fastcall_func(int arg1, double arg2, char arg3);
 HEADER;
 $headername = __DIR__ . '/callconv.h';
 $dllname = __DIR__ . "/callconv_x86.dll";
 
 $ffi1 = FFI::cdef($header, $dllname);
-$ffi1->cdecl_func(1, 2.3);
-$ffi1->stdcall_func(4, 5.6);
-$ffi1->fastcall_func(7, 8.9);
+$ffi1->cdecl_func(1, 2.3, 'a');
+$ffi1->stdcall_func(4, 5.6, 'b');
+$ffi1->fastcall_func(7, 8.9, 'c');
 
 file_put_contents($headername, "#define FFI_LIB \"$dllname\"\n$header");
 
 $ffi2 = FFI::load($headername);
-$ffi2->cdecl_func(2, 3.4);
-$ffi2->stdcall_func(5, 6.7);
-$ffi2->fastcall_func(8, 9.1);
+$ffi2->cdecl_func(2, 3.4, 'a');
+$ffi2->stdcall_func(5, 6.7, 'b');
+$ffi2->fastcall_func(8, 9.1, 'c');
 ?>
 --EXPECT--
-cdecl: 1, 2.300000
-stdcall: 4, 5.600000
-fastcall: 7, 8.900000
-cdecl: 2, 3.400000
-stdcall: 5, 6.700000
-fastcall: 8, 9.100000
+cdecl: 1, 2.300000, a
+stdcall: 4, 5.600000, b
+fastcall: 7, 8.900000, c
+cdecl: 2, 3.400000, a
+stdcall: 5, 6.700000, b
+fastcall: 8, 9.100000, c
 --CLEAN--
 <?php
 unlink(__DIR__ . '/callconv.h');
index f4818d10916842c21a0663df68cbc6608fab8865..f13446ee4e0e3f8689bb83a36cbe3fcf1168e006 100644 (file)
Binary files a/ext/ffi/tests/callconv_x86.dll and b/ext/ffi/tests/callconv_x86.dll differ