wcstok: use security-enhanced version

Replace old wcstok signature with security-enhanced
version, which stores position information between calls in
"context" parameter instead of internal per-thread context.

This allows to get rid of _CRT_NON_CONFORMING_WCSTOK
define in CMakeLists.txt

Reported-by: Kai Schtrom

Signed-off-by: Lev Stipakov <lev@openvpn.net>
pull/477/head
Lev Stipakov 2022-02-02 19:34:28 +02:00 committed by Gert Doering
parent 5c1cae2042
commit cd4748fb25
3 changed files with 7 additions and 6 deletions

View File

@ -67,5 +67,4 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
_UNICODE
UNICODE
WIN32_LEAN_AND_MEAN
HAVE_CONFIG_H
_CRT_NON_CONFORMING_WCSTOK)
HAVE_CONFIG_H)

5
as.c
View File

@ -77,7 +77,8 @@ ExtractProfileName(const WCHAR *profile, const WCHAR *default_name, WCHAR *out_n
WCHAR *buf = _wcsdup(profile);
WCHAR *pch = NULL;
pch = wcstok(buf, L"\r\n");
WCHAR *ctx = NULL;
pch = wcstok_s(buf, L"\r\n", &ctx);
while (pch != NULL) {
if (wcsbegins(pch, PROFILE_NAME_TOKEN)) {
@ -89,7 +90,7 @@ ExtractProfileName(const WCHAR *profile, const WCHAR *default_name, WCHAR *out_n
friendly_name[PROFILE_NAME_LEN - 1] = L'\0';
}
pch = wcstok(NULL, L"\r\n");
pch = wcstok_s(NULL, L"\r\n", &ctx);
}
/* we use .ovpn here, but extension could be customized */

View File

@ -475,7 +475,8 @@ ParseProxyString(LPWSTR proxy_str, url_scheme scheme,
return;
LPCWSTR delim = L"; ";
LPWSTR token = wcstok(proxy_str, delim);
LPWSTR ctx = NULL;
LPWSTR token = wcstok_s(proxy_str, delim, &ctx);
LPCWSTR scheme_str = UrlSchemeStr(scheme);
LPCWSTR socks_str = UrlSchemeStr(SOCKS_URL);
@ -545,7 +546,7 @@ ParseProxyString(LPWSTR proxy_str, url_scheme scheme,
break;
}
token = wcstok(NULL, delim);
token = wcstok_s(NULL, delim, &ctx);
}
}