mirror of
https://github.com/OpenVPN/openvpn.git
synced 2024-09-20 12:02:28 +02:00
openvpnserv: Cache last error before it is overridden
FormatMessage() sets the last error according to its own success. This looses the original error code leading to mismatched error message and error number when sprintfted together resulting in confusing event log message. Signed-off-by: Simon Rozman <simon@rozman.si> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <20210322103957.1234-1-simon@rozman.si> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21789.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
parent
1b71f8597f
commit
1e938c5093
@ -228,12 +228,14 @@ out:
|
||||
LPCTSTR
|
||||
GetLastErrorText()
|
||||
{
|
||||
DWORD error;
|
||||
static TCHAR buf[256];
|
||||
DWORD len;
|
||||
LPTSTR tmp = NULL;
|
||||
|
||||
error = GetLastError();
|
||||
len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
||||
NULL, GetLastError(), LANG_NEUTRAL, (LPTSTR)&tmp, 0, NULL);
|
||||
NULL, error, LANG_NEUTRAL, (LPTSTR)&tmp, 0, NULL);
|
||||
|
||||
if (len == 0 || (long) _countof(buf) < (long) len + 14)
|
||||
{
|
||||
@ -242,7 +244,7 @@ GetLastErrorText()
|
||||
else
|
||||
{
|
||||
tmp[_tcslen(tmp) - 2] = TEXT('\0'); /* remove CR/LF characters */
|
||||
openvpn_sntprintf(buf, _countof(buf), TEXT("%s (0x%x)"), tmp, GetLastError());
|
||||
openvpn_sntprintf(buf, _countof(buf), TEXT("%s (0x%x)"), tmp, error);
|
||||
}
|
||||
|
||||
if (tmp)
|
||||
|
Loading…
Reference in New Issue
Block a user