From 1079962e4c06f88a54e50d997c1b7e84303d30b4 Mon Sep 17 00:00:00 2001 From: Bernhard Schmidt Date: Sat, 15 Aug 2020 21:29:50 +0200 Subject: New upstream version 2.5~beta1 --- src/openvpnserv/common.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/openvpnserv/common.c') diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index eb718d4..958643d 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -31,7 +31,7 @@ static wchar_t win_sys_path[MAX_PATH]; * These are necessary due to certain buggy implementations of (v)snprintf, * that don't guarantee null termination for size > 0. */ -int +BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist) { int len = -1; @@ -40,20 +40,36 @@ openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist) len = _vsntprintf(str, size, format, arglist); str[size - 1] = 0; } - return (len >= 0 && len < size); + return (len >= 0 && (size_t)len < size); } -int + +BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...) +{ + va_list arglist; + BOOL res = FALSE; + if (size > 0) + { + va_start(arglist, format); + res = openvpn_vsntprintf(str, size, format, arglist); + va_end(arglist); + } + return res; +} + +BOOL +openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *const format, ...) { va_list arglist; int len = -1; if (size > 0) { va_start(arglist, format); - len = openvpn_vsntprintf(str, size, format, arglist); + len = vswprintf(str, size, format, arglist); va_end(arglist); + str[size - 1] = L'\0'; } - return len; + return (len >= 0 && len < size); } static DWORD @@ -65,7 +81,7 @@ GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_v if (status == ERROR_FILE_NOT_FOUND && default_value) { size_t len = size/sizeof(data[0]); - if (openvpn_sntprintf(data, len, default_value) > 0) + if (openvpn_sntprintf(data, len, default_value)) { status = ERROR_SUCCESS; } -- cgit v1.2.3 From f2b3dda12a731c2e0971cb7889728edaf23f6cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 29 Nov 2021 20:46:00 +0100 Subject: New upstream version 2.5.4 --- src/openvpnserv/common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/openvpnserv/common.c') diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index 958643d..f7b061c 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -5,7 +5,7 @@ * packet encryption, packet authentication, and * packet compression. * - * Copyright (C) 2011-2018 Heiko Hund + * Copyright (C) 2011-2021 Heiko Hund * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -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) -- cgit v1.2.3