diff --git a/as.c b/as.c index 48327b7..d0e99dd 100644 --- a/as.c +++ b/as.c @@ -662,8 +662,8 @@ again: } swprintf(out_path, out_path_size, L"%ls%ls", out_path, name); out_path[out_path_size - 1] = '\0'; - FILE *f = _wfopen(out_path, L"w"); - if (f == NULL) + FILE *f; + if (_wfopen_s(&f, out_path, L"w")) { MessageBoxW(hWnd, L"Unable to save downloaded profile", _T(PACKAGE_NAME), MB_OK); goto done; diff --git a/config_parser.c b/config_parser.c index a1bad73..1e70cd9 100644 --- a/config_parser.c +++ b/config_parser.c @@ -183,11 +183,7 @@ config_parse(wchar_t *fname) FILE *fd = NULL; config_entry_t *head, *tail; - if (fname) - { - fd = _wfopen(fname, L"r"); - } - if (!fd) + if (!fname || _wfopen_s(&fd, fname, L"r")) { MsgToEventLog(EVENTLOG_ERROR_TYPE, L"Error opening <%ls> in config_parse", fname); return NULL; diff --git a/main.c b/main.c index a64aab8..f1918fe 100644 --- a/main.c +++ b/main.c @@ -202,7 +202,7 @@ _tWinMain(HINSTANCE hThisInstance, #ifdef DEBUG /* Open debug file for output */ - if (!(o.debug_fp = _wfopen(DEBUG_FILE, L"a+,ccs=UTF-8"))) + if (_wfopen_s(&o.debug_fp, DEBUG_FILE, L"a+,ccs=UTF-8")) { /* can't open debug file */ ShowLocalizedMsg(IDS_ERR_OPEN_DEBUG_FILE, DEBUG_FILE); diff --git a/misc.c b/misc.c index 6d811b1..e530a0b 100644 --- a/misc.c +++ b/misc.c @@ -937,8 +937,9 @@ ParseManagementAddress(connection_t *c) wcsncpy_s(pw_path, MAX_PATH, pw_file, _TRUNCATE); } - FILE *fp = _wfopen(pw_path, L"r"); - if (!fp || !fgets(c->manage.password, sizeof(c->manage.password), fp)) + FILE *fp; + if (_wfopen_s(&fp, pw_path, L"r") + || !fgets(c->manage.password, sizeof(c->manage.password), fp)) { /* This may be normal as not all users may be given access to this secret */ ret = false; diff --git a/plap/plap_common.c b/plap/plap_common.c index 854ef16..5686249 100644 --- a/plap/plap_common.c +++ b/plap/plap_common.c @@ -38,7 +38,7 @@ init_debug() { if (!fp) { - fp = _wfopen(L"C:\\Windows\\Temp\\openvpn-plap-debug.txt", L"a+,ccs=UTF-8"); + _wfopen_s(&fp, L"C:\\Windows\\Temp\\openvpn-plap-debug.txt", L"a+,ccs=UTF-8"); } InitializeCriticalSection(&log_write); }