[Openvpn-devel] dco-win: use proper calling convention on x86

Message ID 20230131122542.1887-1-lstipakov@gmail.com
State Superseded
Headers show
Series [Openvpn-devel] dco-win: use proper calling convention on x86 | expand

Commit Message

Lev Stipakov Jan. 31, 2023, 12:25 p.m. UTC
From: Lev Stipakov <lev@openvpn.net>

WinAPI uses __stdcall calling convention on x86. Wrong
calling convention causes UB, which in this case breaks
dco-win functionality.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
---
 src/openvpn/dco_win.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Timo Rothenpieler Jan. 31, 2023, 12:39 p.m. UTC | #1
On 31/01/2023 13:25, Lev Stipakov wrote:
> From: Lev Stipakov <lev@openvpn.net>
> 
> WinAPI uses __stdcall calling convention on x86. Wrong
> calling convention causes UB, which in this case breaks
> dco-win functionality.
> 
> Signed-off-by: Lev Stipakov <lev@openvpn.net>
> ---
>   src/openvpn/dco_win.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c
> index 7594024c..da1e1fbc 100644
> --- a/src/openvpn/dco_win.c
> +++ b/src/openvpn/dco_win.c
> @@ -110,7 +110,7 @@ dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, struct signal_info
>   {
>       volatile int *signal_received = &sig_info->signal_received;
>       /* GetOverlappedResultEx is available starting from Windows 8 */
> -    typedef BOOL (*get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
> +    typedef BOOL (__stdcall *get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);

Wouldn't it be better to use the WINAPI Macro here, so it's the right 
calling convention no matter the arch?

Not sure what header it's defined in, but a quick search suggests it 
comes from minwindef.h.

>       get_overlapped_result_ex_t get_overlapped_result_ex =
>           (get_overlapped_result_ex_t)GetProcAddress(GetModuleHandle("Kernel32.dll"),
>                                                      "GetOverlappedResultEx");

Patch

diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c
index 7594024c..da1e1fbc 100644
--- a/src/openvpn/dco_win.c
+++ b/src/openvpn/dco_win.c
@@ -110,7 +110,7 @@  dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, struct signal_info
 {
     volatile int *signal_received = &sig_info->signal_received;
     /* GetOverlappedResultEx is available starting from Windows 8 */
-    typedef BOOL (*get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
+    typedef BOOL (__stdcall *get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
     get_overlapped_result_ex_t get_overlapped_result_ex =
         (get_overlapped_result_ex_t)GetProcAddress(GetModuleHandle("Kernel32.dll"),
                                                    "GetOverlappedResultEx");