diff options
author | Lev Stipakov | 2022-05-03 03:28:40 +0300 |
---|---|---|
committer | Gert Doering | 2022-05-12 08:25:15 +0200 |
commit | 54800aa975418fe3570f3206a5f9b277dc59bd47 (patch) | |
tree | 66ddd9a5c4b0ca890559fb7bec95053f1484ac11 /src/openvpn/manage.c | |
parent | 043c67f36342969cd171d24c70ee6b62ebc95fee (diff) | |
download | openvpn-54800aa975418fe3570f3206a5f9b277dc59bd47.zip openvpn-54800aa975418fe3570f3206a5f9b277dc59bd47.tar.gz |
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.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Selva Nair <selva.nair@gmail.com>
Message-Id: <20220503002840.295-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24270.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Diffstat (limited to 'src/openvpn/manage.c')
-rw-r--r-- | src/openvpn/manage.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index e305e44..aeea5f9 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -2008,9 +2008,10 @@ man_process_command(struct management *man, const char *line) static bool man_io_error(struct management *man, const char *prefix) { - const int err = openvpn_errno(); + bool crt_error = false; + int err = openvpn_errno_maybe_crt(&crt_error); - if (!ignore_sys_error(err)) + if (!ignore_sys_error(err, crt_error)) { struct gc_arena gc = gc_new(); msg(D_MANAGEMENT, "MANAGEMENT: TCP %s error: %s", prefix, |