]> git.ipfire.org Git - thirdparty/openvpn.git/commit
Fix M_ERRNO behavior on Windows
authorLev Stipakov <lev@openvpn.net>
Wed, 4 May 2022 09:13:05 +0000 (12:13 +0300)
committerGert Doering <gert@greenie.muc.de>
Thu, 12 May 2022 06:35:08 +0000 (08:35 +0200)
commit4e5b14012550bf934dcf850547b542afa4d6605a
treeb9c8e380eeb7df444e0b8154034ec6772356d904
parent55cfc0b9541ff25fac31059ffcf7eea06fd6c0ec
Fix M_ERRNO behavior on Windows

We use M_ERRNO flag in logging to display error code
and error message. This has been broken on Windows,
where we use error code from GetLastError() and
error description from strerror(). strerror() expects
C runtime error code, which is quite different from
last error code from WinAPI call. As a result, we got
incorrect error description.

The ultimate fix would be introducing another flag
for WinAPI errors, like M_WINERR and use either that or
M_ERRNO depends on context. However, the change would be
quite intrusive and in some cases it is hard to say which
one to use without looking into internals.

Instead we stick to M_ERRNO and in Windows case we
first try to obtain error code from GetLastError() and
if it returns ERROR_SUCCESS (which is 0), we assume that
we have C runtime error and use errno. To get error
description we use strerror_win32() with GetLastError()
and strerror() with errno.

strerror_win32() uses FormatMessage() internally, which
is the right way to get WinAPI error description.

This commit is the backport of 54800aa975418fe3570f3206a5f9b277dc59bd47,
adjusted for the different code base related to socket errors (print
socket file descriptor) in x_check_status().

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20220504091305.434-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24274.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/error.c
src/openvpn/error.h
src/openvpn/forward.c
src/openvpn/manage.c
src/openvpn/platform.c
src/openvpn/tun.h