From 26003e59cc4e37c49bd44f5a062403da178d8acc Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 17 Sep 2024 16:56:03 +0200 Subject: [PATCH 1/6] [va_list] initialize with ={0}; --- channels/location/client/location_main.c | 2 +- channels/rdpdr/client/rdpdr_main.c | 2 +- channels/urbdrc/client/libusb/libusb_udevice.c | 2 +- client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp | 8 ++++---- client/SDL/SDL2/dialogs/sdl_dialogs.cpp | 10 +++++----- client/SDL/SDL2/dialogs/sdl_selectlist.cpp | 2 +- client/SDL/SDL2/sdl_freerdp.cpp | 6 +++--- client/SDL/SDL2/sdl_utils.cpp | 4 ++-- client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp | 8 ++++---- client/SDL/SDL3/dialogs/sdl_dialogs.cpp | 10 +++++----- client/SDL/SDL3/dialogs/sdl_selectlist.cpp | 2 +- client/SDL/SDL3/sdl_freerdp.cpp | 6 +++--- client/SDL/SDL3/sdl_utils.cpp | 4 ++-- client/SDL/common/aad/sdl_webview.cpp | 2 +- client/X11/xf_utils.c | 2 +- client/common/client.c | 2 +- client/common/client_cliprdr_file.c | 2 +- client/common/file.c | 2 +- client/common/test/TestClientRdpFile.c | 2 +- libfreerdp/codec/dsp_fdk_aac.c | 2 +- libfreerdp/core/aad.c | 2 +- libfreerdp/core/freerdp.c | 2 +- libfreerdp/core/gateway/http.c | 6 +++--- libfreerdp/core/gateway/tsg.c | 2 +- libfreerdp/core/test/TestConnect.c | 2 +- libfreerdp/core/timezone.c | 2 +- winpr/libwinpr/comm/comm.c | 2 +- winpr/libwinpr/crt/string.c | 4 ++-- winpr/libwinpr/timezone/timezone.c | 2 +- winpr/libwinpr/utils/collections/ArrayList.c | 2 +- winpr/libwinpr/utils/collections/PubSub.c | 4 ++-- 31 files changed, 55 insertions(+), 55 deletions(-) diff --git a/channels/location/client/location_main.c b/channels/location/client/location_main.c index e0b3854f5..ec822c326 100644 --- a/channels/location/client/location_main.c +++ b/channels/location/client/location_main.c @@ -343,7 +343,7 @@ static UINT location_send(LocationClientContext* context, LOCATION_PDUTYPE type, WINPR_ASSERT(callback); UINT32 res = ERROR_INTERNAL_ERROR; - va_list ap; + va_list ap = { 0 }; va_start(ap, count); switch (type) { diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 6203e33a0..0263d415e 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -1646,7 +1646,7 @@ static const char* state_str(size_t count, va_list ap, char* buffer, size_t size static BOOL rdpdr_state_check(rdpdrPlugin* rdpdr, UINT16 packetid, enum RDPDR_CHANNEL_STATE next, size_t count, ...) { - va_list ap; + va_list ap = { 0 }; WINPR_ASSERT(rdpdr); va_start(ap, count); diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index 5dfb43e90..f587c66c3 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -139,7 +139,7 @@ static BOOL log_libusb_result_(wLog* log, DWORD lvl, WINPR_FORMAT_ARG const char if (error < 0) { char buffer[8192] = { 0 }; - va_list ap; + va_list ap = { 0 }; va_start(ap, error); (void)vsnprintf(buffer, sizeof(buffer), fmt, ap); va_end(ap); diff --git a/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp b/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp index c4c18642d..bb676c4d7 100644 --- a/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp +++ b/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp @@ -58,7 +58,7 @@ bool SDLConnectionDialog::visible() const bool SDLConnectionDialog::setTitle(const char* fmt, ...) { std::lock_guard lock(_mux); - va_list ap; + va_list ap = {}; va_start(ap, fmt); _title = print(fmt, ap); va_end(ap); @@ -68,7 +68,7 @@ bool SDLConnectionDialog::setTitle(const char* fmt, ...) bool SDLConnectionDialog::showInfo(const char* fmt, ...) { - va_list ap; + va_list ap = {}; va_start(ap, fmt); auto rc = show(MSG_INFO, fmt, ap); va_end(ap); @@ -77,7 +77,7 @@ bool SDLConnectionDialog::showInfo(const char* fmt, ...) bool SDLConnectionDialog::showWarn(const char* fmt, ...) { - va_list ap; + va_list ap = {}; va_start(ap, fmt); auto rc = show(MSG_WARN, fmt, ap); va_end(ap); @@ -86,7 +86,7 @@ bool SDLConnectionDialog::showWarn(const char* fmt, ...) bool SDLConnectionDialog::showError(const char* fmt, ...) { - va_list ap; + va_list ap = {}; va_start(ap, fmt); auto rc = show(MSG_ERROR, fmt, ap); va_end(ap); diff --git a/client/SDL/SDL2/dialogs/sdl_dialogs.cpp b/client/SDL/SDL2/dialogs/sdl_dialogs.cpp index 54dfd4e13..eea01e354 100644 --- a/client/SDL/SDL2/dialogs/sdl_dialogs.cpp +++ b/client/SDL/SDL2/dialogs/sdl_dialogs.cpp @@ -53,7 +53,7 @@ static const char* type_str_for_flags(UINT32 flags) static BOOL sdl_wait_for_result(rdpContext* context, Uint32 type, SDL_Event* result) { - const SDL_Event empty = { 0 }; + const SDL_Event empty = {}; WINPR_ASSERT(context); WINPR_ASSERT(result); @@ -72,7 +72,7 @@ static BOOL sdl_wait_for_result(rdpContext* context, Uint32 type, SDL_Event* res static int sdl_show_dialog(rdpContext* context, const char* title, const char* message, Sint32 flags) { - SDL_Event event = { 0 }; + SDL_Event event = {}; if (!sdl_push_user_event(SDL_USEREVENT_SHOW_DIALOG, title, message, flags)) return 0; @@ -86,7 +86,7 @@ static int sdl_show_dialog(rdpContext* context, const char* title, const char* m BOOL sdl_authenticate_ex(freerdp* instance, char** username, char** password, char** domain, rdp_auth_reason reason) { - SDL_Event event = { 0 }; + SDL_Event event = {}; BOOL res = FALSE; SDLConnectionDialogHider hider(instance); @@ -185,7 +185,7 @@ BOOL sdl_choose_smartcard(freerdp* instance, SmartcardCertInfo** cert_list, DWOR list.push_back(m.c_str()); } - SDL_Event event = { 0 }; + SDL_Event event = {}; const char* title = "Select a logon smartcard certificate"; if (gateway) title = "Select a gateway logon smartcard certificate"; @@ -317,7 +317,7 @@ static DWORD sdl_show_ceritifcate_dialog(rdpContext* context, const char* title, if (!sdl_push_user_event(SDL_USEREVENT_CERT_DIALOG, title, message)) return 0; - SDL_Event event = { 0 }; + SDL_Event event = {}; if (!sdl_wait_for_result(context, SDL_USEREVENT_CERT_RESULT, &event)) return 0; return static_cast(event.user.code); diff --git a/client/SDL/SDL2/dialogs/sdl_selectlist.cpp b/client/SDL/SDL2/dialogs/sdl_selectlist.cpp index 200543113..0263694a1 100644 --- a/client/SDL/SDL2/dialogs/sdl_selectlist.cpp +++ b/client/SDL/SDL2/dialogs/sdl_selectlist.cpp @@ -63,7 +63,7 @@ int SdlSelectList::run() if (!_buttons.update(_renderer)) throw; - SDL_Event event = { 0 }; + SDL_Event event = {}; SDL_WaitEvent(&event); switch (event.type) { diff --git a/client/SDL/SDL2/sdl_freerdp.cpp b/client/SDL/SDL2/sdl_freerdp.cpp index 3568d71bd..3b2373c87 100644 --- a/client/SDL/SDL2/sdl_freerdp.cpp +++ b/client/SDL/SDL2/sdl_freerdp.cpp @@ -665,7 +665,7 @@ static const char* sdl_window_get_title(rdpSettings* settings) addPort = (port != 3389); - char buffer[MAX_PATH + 64] = { 0 }; + char buffer[MAX_PATH + 64] = {}; if (!addPort) (void)sprintf_s(buffer, sizeof(buffer), "%s %s", prefix, name); @@ -837,7 +837,7 @@ static int sdl_run(SdlContext* sdl) while (!shall_abort(sdl)) { - SDL_Event windowEvent = { 0 }; + SDL_Event windowEvent = {}; while (!shall_abort(sdl) && SDL_WaitEventTimeout(nullptr, 1000)) { /* Only poll standard SDL events and SDL_USEREVENTS meant to create dialogs. @@ -1413,7 +1413,7 @@ static DWORD WINAPI sdl_client_thread_proc(SdlContext* sdl) static BOOL sdl_client_global_init() { #if defined(_WIN32) - WSADATA wsaData = { 0 }; + WSADATA wsaData = {}; const DWORD wVersionRequested = MAKEWORD(1, 1); const int rc = WSAStartup(wVersionRequested, &wsaData); if (rc != 0) diff --git a/client/SDL/SDL2/sdl_utils.cpp b/client/SDL/SDL2/sdl_utils.cpp index b7729f1fe..7fdd48065 100644 --- a/client/SDL/SDL2/sdl_utils.cpp +++ b/client/SDL/SDL2/sdl_utils.cpp @@ -152,7 +152,7 @@ BOOL sdl_push_user_event(Uint32 type, ...) SDL_Event ev = {}; SDL_UserEvent* event = &ev.user; - va_list ap; + va_list ap = {}; va_start(ap, type); event->type = type; switch (type) @@ -285,7 +285,7 @@ HANDLE WinPREvent::handle() const bool sdl_push_quit() { - SDL_Event ev = { 0 }; + SDL_Event ev = {}; ev.type = SDL_QUIT; SDL_PushEvent(&ev); return true; diff --git a/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp b/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp index 45b800f13..28a30f9d8 100644 --- a/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp +++ b/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp @@ -58,7 +58,7 @@ bool SDLConnectionDialog::visible() const bool SDLConnectionDialog::setTitle(const char* fmt, ...) { std::lock_guard lock(_mux); - va_list ap; + va_list ap = {}; va_start(ap, fmt); _title = print(fmt, ap); va_end(ap); @@ -68,7 +68,7 @@ bool SDLConnectionDialog::setTitle(const char* fmt, ...) bool SDLConnectionDialog::showInfo(const char* fmt, ...) { - va_list ap; + va_list ap = {}; va_start(ap, fmt); auto rc = show(MSG_INFO, fmt, ap); va_end(ap); @@ -77,7 +77,7 @@ bool SDLConnectionDialog::showInfo(const char* fmt, ...) bool SDLConnectionDialog::showWarn(const char* fmt, ...) { - va_list ap; + va_list ap = {}; va_start(ap, fmt); auto rc = show(MSG_WARN, fmt, ap); va_end(ap); @@ -86,7 +86,7 @@ bool SDLConnectionDialog::showWarn(const char* fmt, ...) bool SDLConnectionDialog::showError(const char* fmt, ...) { - va_list ap; + va_list ap = {}; va_start(ap, fmt); auto rc = show(MSG_ERROR, fmt, ap); va_end(ap); diff --git a/client/SDL/SDL3/dialogs/sdl_dialogs.cpp b/client/SDL/SDL3/dialogs/sdl_dialogs.cpp index af6c7e9b2..817efc043 100644 --- a/client/SDL/SDL3/dialogs/sdl_dialogs.cpp +++ b/client/SDL/SDL3/dialogs/sdl_dialogs.cpp @@ -53,7 +53,7 @@ static const char* type_str_for_flags(UINT32 flags) static BOOL sdl_wait_for_result(rdpContext* context, Uint32 type, SDL_Event* result) { - const SDL_Event empty = { 0 }; + const SDL_Event empty = {}; WINPR_ASSERT(context); WINPR_ASSERT(result); @@ -72,7 +72,7 @@ static BOOL sdl_wait_for_result(rdpContext* context, Uint32 type, SDL_Event* res static int sdl_show_dialog(rdpContext* context, const char* title, const char* message, Sint32 flags) { - SDL_Event event = { 0 }; + SDL_Event event = {}; if (!sdl_push_user_event(SDL_EVENT_USER_SHOW_DIALOG, title, message, flags)) return 0; @@ -86,7 +86,7 @@ static int sdl_show_dialog(rdpContext* context, const char* title, const char* m BOOL sdl_authenticate_ex(freerdp* instance, char** username, char** password, char** domain, rdp_auth_reason reason) { - SDL_Event event = { 0 }; + SDL_Event event = {}; BOOL res = FALSE; SDLConnectionDialogHider hider(instance); @@ -185,7 +185,7 @@ BOOL sdl_choose_smartcard(freerdp* instance, SmartcardCertInfo** cert_list, DWOR list.push_back(m.c_str()); } - SDL_Event event = { 0 }; + SDL_Event event = {}; const char* title = "Select a logon smartcard certificate"; if (gateway) title = "Select a gateway logon smartcard certificate"; @@ -315,7 +315,7 @@ static DWORD sdl_show_ceritifcate_dialog(rdpContext* context, const char* title, if (!sdl_push_user_event(SDL_EVENT_USER_CERT_DIALOG, title, message)) return 0; - SDL_Event event = { 0 }; + SDL_Event event = {}; if (!sdl_wait_for_result(context, SDL_EVENT_USER_CERT_RESULT, &event)) return 0; return static_cast(event.user.code); diff --git a/client/SDL/SDL3/dialogs/sdl_selectlist.cpp b/client/SDL/SDL3/dialogs/sdl_selectlist.cpp index 9b84fb22f..1fb0291b2 100644 --- a/client/SDL/SDL3/dialogs/sdl_selectlist.cpp +++ b/client/SDL/SDL3/dialogs/sdl_selectlist.cpp @@ -62,7 +62,7 @@ int SdlSelectList::run() if (!_buttons.update(_renderer)) throw; - SDL_Event event = { 0 }; + SDL_Event event = {}; SDL_WaitEvent(&event); switch (event.type) { diff --git a/client/SDL/SDL3/sdl_freerdp.cpp b/client/SDL/SDL3/sdl_freerdp.cpp index 76611518c..6c5603bdd 100644 --- a/client/SDL/SDL3/sdl_freerdp.cpp +++ b/client/SDL/SDL3/sdl_freerdp.cpp @@ -663,7 +663,7 @@ static const char* sdl_window_get_title(rdpSettings* settings) addPort = (port != 3389); - char buffer[MAX_PATH + 64] = { 0 }; + char buffer[MAX_PATH + 64] = {}; if (!addPort) sprintf_s(buffer, sizeof(buffer), "%s %s", prefix, name); @@ -828,7 +828,7 @@ static int sdl_run(SdlContext* sdl) while (!shall_abort(sdl)) { - SDL_Event windowEvent = { 0 }; + SDL_Event windowEvent = {}; while (!shall_abort(sdl) && SDL_WaitEventTimeout(nullptr, 1000)) { /* Only poll standard SDL events and SDL_EVENT_USERS meant to create dialogs. @@ -1397,7 +1397,7 @@ static DWORD WINAPI sdl_client_thread_proc(SdlContext* sdl) static BOOL sdl_client_global_init() { #if defined(_WIN32) - WSADATA wsaData = { 0 }; + WSADATA wsaData = {}; const DWORD wVersionRequested = MAKEWORD(1, 1); const int rc = WSAStartup(wVersionRequested, &wsaData); if (rc != 0) diff --git a/client/SDL/SDL3/sdl_utils.cpp b/client/SDL/SDL3/sdl_utils.cpp index e46edb634..e2234d659 100644 --- a/client/SDL/SDL3/sdl_utils.cpp +++ b/client/SDL/SDL3/sdl_utils.cpp @@ -198,7 +198,7 @@ BOOL sdl_push_user_event(Uint32 type, ...) SDL_Event ev = {}; SDL_UserEvent* event = &ev.user; - va_list ap; + va_list ap = {}; va_start(ap, type); event->type = type; switch (type) @@ -331,7 +331,7 @@ HANDLE WinPREvent::handle() const bool sdl_push_quit() { - SDL_Event ev = { 0 }; + SDL_Event ev = {}; ev.type = SDL_EVENT_QUIT; SDL_PushEvent(&ev); return true; diff --git a/client/SDL/common/aad/sdl_webview.cpp b/client/SDL/common/aad/sdl_webview.cpp index b4df75b8f..c887f9061 100644 --- a/client/SDL/common/aad/sdl_webview.cpp +++ b/client/SDL/common/aad/sdl_webview.cpp @@ -107,7 +107,7 @@ BOOL sdl_webview_get_access_token(freerdp* instance, AccessTokenType tokenType, "ACCESS_TOKEN_TYPE_AAD expected 2 additional arguments, but got %" PRIuz ", ignoring", count); - va_list ap; + va_list ap = {}; va_start(ap, count); const char* scope = va_arg(ap, const char*); const char* req_cnf = va_arg(ap, const char*); diff --git a/client/X11/xf_utils.c b/client/X11/xf_utils.c index e9e28c904..7355e2587 100644 --- a/client/X11/xf_utils.c +++ b/client/X11/xf_utils.c @@ -34,7 +34,7 @@ static const DWORD log_level = WLOG_TRACE; static void write_log(wLog* log, DWORD level, const char* fname, const char* fkt, size_t line, ...) { - va_list ap; + va_list ap = { 0 }; va_start(ap, line); WLog_PrintMessageVA(log, WLOG_MESSAGE_TEXT, level, line, fname, fkt, ap); va_end(ap); diff --git a/client/common/client.c b/client/common/client.c index 001ae7571..3d0b5ddf8 100644 --- a/client/common/client.c +++ b/client/common/client.c @@ -1127,7 +1127,7 @@ BOOL client_cli_get_access_token(freerdp* instance, AccessTokenType tokenType, c "ACCESS_TOKEN_TYPE_AAD expected 2 additional arguments, but got %" PRIuz ", ignoring", count); - va_list ap; + va_list ap = { 0 }; va_start(ap, count); const char* scope = va_arg(ap, const char*); const char* req_cnf = va_arg(ap, const char*); diff --git a/client/common/client_cliprdr_file.c b/client/common/client_cliprdr_file.c index 2f20327e0..2406cf389 100644 --- a/client/common/client_cliprdr_file.c +++ b/client/common/client_cliprdr_file.c @@ -625,7 +625,7 @@ static void writelog(wLog* log, DWORD level, const char* fname, const char* fkt, if (!WLog_IsLevelActive(log, level)) return; - va_list ap; + va_list ap = { 0 }; va_start(ap, line); WLog_PrintMessageVA(log, WLOG_MESSAGE_TEXT, level, line, fname, fkt, ap); va_end(ap); diff --git a/client/common/file.c b/client/common/file.c index c4634f059..5ddeb0c3b 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -1425,7 +1425,7 @@ WINPR_ATTR_FORMAT_ARG(3, 4) static SSIZE_T freerdp_client_write_setting_to_buffer(char** buffer, size_t* bufferSize, WINPR_FORMAT_ARG const char* fmt, ...) { - va_list ap; + va_list ap = { 0 }; SSIZE_T len = 0; char* buf = NULL; size_t bufSize = 0; diff --git a/client/common/test/TestClientRdpFile.c b/client/common/test/TestClientRdpFile.c index e51123e72..03f1bc3b6 100644 --- a/client/common/test/TestClientRdpFile.c +++ b/client/common/test/TestClientRdpFile.c @@ -239,7 +239,7 @@ static char* append(const char* fmt, ...) { int rc = 0; char* dst = NULL; - va_list ap; + va_list ap = { 0 }; va_start(ap, fmt); rc = vsnprintf(NULL, 0, fmt, ap); diff --git a/libfreerdp/codec/dsp_fdk_aac.c b/libfreerdp/codec/dsp_fdk_aac.c index 93227477c..2165863ce 100644 --- a/libfreerdp/codec/dsp_fdk_aac.c +++ b/libfreerdp/codec/dsp_fdk_aac.c @@ -32,7 +32,7 @@ static void write_log(unsigned log_level, const char* fmt, ...) { char buffer[1024] = { 0 }; - va_list ap; + va_list ap = { 0 }; va_start(ap, fmt); vsnprintf(buffer, sizeof(buffer), fmt, ap); va_end(ap); diff --git a/libfreerdp/core/aad.c b/libfreerdp/core/aad.c index 6f946230d..8b40cbe1f 100644 --- a/libfreerdp/core/aad.c +++ b/libfreerdp/core/aad.c @@ -57,7 +57,7 @@ static BOOL generate_pop_key(rdpAad* aad); WINPR_ATTR_FORMAT_ARG(2, 3) static SSIZE_T stream_sprintf(wStream* s, WINPR_FORMAT_ARG const char* fmt, ...) { - va_list ap; + va_list ap = { 0 }; va_start(ap, fmt); const int rc = vsnprintf(NULL, 0, fmt, ap); va_end(ap); diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index a42f66689..ae55fe34a 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -1302,7 +1302,7 @@ void clearChannelError(rdpContext* context) WINPR_ATTR_FORMAT_ARG(3, 4) void setChannelError(rdpContext* context, UINT errorNum, WINPR_FORMAT_ARG const char* format, ...) { - va_list ap; + va_list ap = { 0 }; va_start(ap, format); WINPR_ASSERT(context); diff --git a/libfreerdp/core/gateway/http.c b/libfreerdp/core/gateway/http.c index 9ff9bd906..aa1e3027a 100644 --- a/libfreerdp/core/gateway/http.c +++ b/libfreerdp/core/gateway/http.c @@ -345,7 +345,7 @@ BOOL http_context_set_pragma(HttpContext* context, WINPR_FORMAT_ARG const char* free(context->Pragma); context->Pragma = NULL; - va_list ap; + va_list ap = { 0 }; va_start(ap, Pragma); return list_append(context, Pragma, ap); } @@ -356,7 +356,7 @@ BOOL http_context_append_pragma(HttpContext* context, const char* Pragma, ...) if (!context || !Pragma) return FALSE; - va_list ap; + va_list ap = { 0 }; va_start(ap, Pragma); return list_append(context, Pragma, ap); } @@ -551,7 +551,7 @@ WINPR_ATTR_FORMAT_ARG(2, 3) static BOOL http_encode_print(wStream* s, WINPR_FORMAT_ARG const char* fmt, ...) { char* str = NULL; - va_list ap; + va_list ap = { 0 }; int length = 0; int used = 0; diff --git a/libfreerdp/core/gateway/tsg.c b/libfreerdp/core/gateway/tsg.c index 06592d5d0..da0b7d339 100644 --- a/libfreerdp/core/gateway/tsg.c +++ b/libfreerdp/core/gateway/tsg.c @@ -762,7 +762,7 @@ WINPR_ATTR_FORMAT_ARG(3, 4) static BOOL tsg_print(char** buffer, size_t* len, WINPR_FORMAT_ARG const char* fmt, ...) { int rc = 0; - va_list ap; + va_list ap = { 0 }; if (!buffer || !len || !fmt) return FALSE; va_start(ap, fmt); diff --git a/libfreerdp/core/test/TestConnect.c b/libfreerdp/core/test/TestConnect.c index 31f6019ef..24874a622 100644 --- a/libfreerdp/core/test/TestConnect.c +++ b/libfreerdp/core/test/TestConnect.c @@ -186,7 +186,7 @@ static int testAbort(int port) static char* concatenate(size_t count, ...) { char* rc = NULL; - va_list ap; + va_list ap = { 0 }; va_start(ap, count); rc = _strdup(va_arg(ap, char*)); for (size_t x = 1; x < count; x++) diff --git a/libfreerdp/core/timezone.c b/libfreerdp/core/timezone.c index 4facc0874..cfd225304 100644 --- a/libfreerdp/core/timezone.c +++ b/libfreerdp/core/timezone.c @@ -78,7 +78,7 @@ static void log_print(wLog* log, DWORD level, const char* file, const char* fkt, if (!WLog_IsLevelActive(log, level)) return; - va_list ap; + va_list ap = { 0 }; va_start(ap, line); WLog_PrintMessageVA(log, WLOG_MESSAGE_TEXT, level, line, file, fkt, ap); va_end(ap); diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c index dc4b02eb4..8ac2a2b2f 100644 --- a/winpr/libwinpr/comm/comm.c +++ b/winpr/libwinpr/comm/comm.c @@ -134,7 +134,7 @@ void CommLog_Print(DWORD level, ...) if (!CommInitialized()) return; - va_list ap; + va_list ap = { 0 }; va_start(ap, level); WLog_PrintVA(sLog, level, ap); va_end(ap); diff --git a/winpr/libwinpr/crt/string.c b/winpr/libwinpr/crt/string.c index e385276f7..d0bd38495 100644 --- a/winpr/libwinpr/crt/string.c +++ b/winpr/libwinpr/crt/string.c @@ -177,7 +177,7 @@ BOOL winpr_str_append(const char* what, char* buffer, size_t size, const char* s WINPR_ATTR_FORMAT_ARG(3, 4) int winpr_asprintf(char** s, size_t* slen, WINPR_FORMAT_ARG const char* templ, ...) { - va_list ap; + va_list ap = { 0 }; va_start(ap, templ); int rc = winpr_vasprintf(s, slen, templ, ap); @@ -188,7 +188,7 @@ int winpr_asprintf(char** s, size_t* slen, WINPR_FORMAT_ARG const char* templ, . WINPR_ATTR_FORMAT_ARG(3, 0) int winpr_vasprintf(char** s, size_t* slen, WINPR_FORMAT_ARG const char* templ, va_list oap) { - va_list ap; + va_list ap = { 0 }; *s = NULL; *slen = 0; diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index 3f179f39c..7b8422bf6 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -595,7 +595,7 @@ static void log_print(wLog* log, DWORD level, const char* file, const char* fkt, if (!WLog_IsLevelActive(log, level)) return; - va_list ap; + va_list ap = { 0 }; va_start(ap, line); WLog_PrintMessageVA(log, WLOG_MESSAGE_TEXT, level, line, file, fkt, ap); va_end(ap); diff --git a/winpr/libwinpr/utils/collections/ArrayList.c b/winpr/libwinpr/utils/collections/ArrayList.c index 2f8ff9182..05d5afb5c 100644 --- a/winpr/libwinpr/utils/collections/ArrayList.c +++ b/winpr/libwinpr/utils/collections/ArrayList.c @@ -529,7 +529,7 @@ wObject* ArrayList_Object(wArrayList* arrayList) BOOL ArrayList_ForEach(wArrayList* arrayList, ArrayList_ForEachFkt fkt, ...) { BOOL rc = 0; - va_list ap; + va_list ap = { 0 }; va_start(ap, fkt); rc = ArrayList_ForEachAP(arrayList, fkt, ap); va_end(ap); diff --git a/winpr/libwinpr/utils/collections/PubSub.c b/winpr/libwinpr/utils/collections/PubSub.c index b95f26d02..4ab29ab81 100644 --- a/winpr/libwinpr/utils/collections/PubSub.c +++ b/winpr/libwinpr/utils/collections/PubSub.c @@ -121,7 +121,7 @@ int PubSub_Subscribe(wPubSub* pubSub, const char* EventName, ...) int status = -1; WINPR_ASSERT(pubSub); - va_list ap; + va_list ap = { 0 }; va_start(ap, EventName); pEventHandler EventHandler = va_arg(ap, pEventHandler); @@ -154,7 +154,7 @@ int PubSub_Unsubscribe(wPubSub* pubSub, const char* EventName, ...) WINPR_ASSERT(pubSub); WINPR_ASSERT(EventName); - va_list ap; + va_list ap = { 0 }; va_start(ap, EventName); pEventHandler EventHandler = va_arg(ap, pEventHandler); From 0fe89241f8bee5742a5b6b1b631ca660ad407346 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 17 Sep 2024 17:11:26 +0200 Subject: [PATCH 2/6] [core,client] add argument checks & assertions * freerdp_get_event_handles * freerdp_channels_process_pending_messages --- libfreerdp/core/client.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libfreerdp/core/client.c b/libfreerdp/core/client.c index 12285403a..6dd45d6cf 100644 --- a/libfreerdp/core/client.c +++ b/libfreerdp/core/client.c @@ -198,10 +198,15 @@ void freerdp_channels_free(rdpChannels* channels) return; HashTable_Free(channels->channelEvents); - MessageQueue_Free(channels->queue); DeleteCriticalSection(&channels->channelsLock); + if (channels->queue) + { + MessageQueue_Free(channels->queue); + channels->queue = NULL; + } + free(channels); } @@ -719,8 +724,8 @@ BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance, void** r void* freerdp_channels_get_static_channel_interface(rdpChannels* channels, const char* name) { void* pInterface = NULL; - CHANNEL_OPEN_DATA* pChannelOpenData = NULL; - pChannelOpenData = freerdp_channels_find_channel_open_data_by_name(channels, name); + CHANNEL_OPEN_DATA* pChannelOpenData = + freerdp_channels_find_channel_open_data_by_name(channels, name); if (pChannelOpenData) pInterface = pChannelOpenData->pInterface; @@ -730,7 +735,9 @@ void* freerdp_channels_get_static_channel_interface(rdpChannels* channels, const HANDLE freerdp_channels_get_event_handle(freerdp* instance) { - WINPR_ASSERT(instance); + if (!instance) + return INVALID_HANDLE_VALUE; + WINPR_ASSERT(instance->context); rdpChannels* channels = instance->context->channels; @@ -753,13 +760,16 @@ static BOOL channels_process(const void* key, void* value, void* arg) int freerdp_channels_process_pending_messages(freerdp* instance) { - WINPR_ASSERT(instance); + if (!instance) + return -1; + WINPR_ASSERT(instance->context); rdpChannels* channels = instance->context->channels; WINPR_ASSERT(channels); - if (WaitForSingleObject(MessageQueue_Event(channels->queue), 0) == WAIT_OBJECT_0) + const DWORD status = WaitForSingleObject(MessageQueue_Event(channels->queue), 0); + if (status == WAIT_OBJECT_0) { if (!freerdp_channels_process_sync(channels, instance)) return -1; From 3d210d815d5c7f6a38db96127f3bf677228dfca7 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 24 Sep 2024 11:30:23 +0200 Subject: [PATCH 3/6] [client,X11] fix sign of shifted type --- client/X11/xf_window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 0c17646a3..3ba208f8e 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -204,7 +204,7 @@ const char* window_styles_ex_to_string(UINT32 styleEx, char* buffer, size_t leng const char* sep = ""; for (size_t x = 0; x < 32; x++) { - const UINT32 val = 1 << x; + const UINT32 val = 1UL << x; if ((styleEx & val) != 0) { const char* str = window_style_ex_to_string(val); From 1f3e6decf295e8a9036a3cd9127c37570ec36270 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 24 Sep 2024 11:31:40 +0200 Subject: [PATCH 4/6] [client,common] fix possible integer overflow --- client/common/cmdline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 00e6c7cf8..85c3dc773 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -441,7 +441,7 @@ static size_t print_description(const char* text, size_t start_offset, size_t cu const int rc = printf("\n"); if (rc >= 0) { - WINPR_ASSERT(SIZE_MAX - rc >= current); + WINPR_ASSERT(SIZE_MAX - rc > current); current += (size_t)rc; } return current; From 89e6f357b5c3df73945ad6e85538876e0b9c13ca Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 24 Sep 2024 11:34:02 +0200 Subject: [PATCH 5/6] [utils,smartcard] fix possible integer overflow --- libfreerdp/utils/smartcard_call.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libfreerdp/utils/smartcard_call.c b/libfreerdp/utils/smartcard_call.c index aa1fb264e..9a3b3916d 100644 --- a/libfreerdp/utils/smartcard_call.c +++ b/libfreerdp/utils/smartcard_call.c @@ -227,6 +227,7 @@ static LONG smartcard_ListReaderGroupsW_Call(scard_call_context* smartcard, wStr ret.msz = (BYTE*)mszGroups; + WINPR_ASSERT(cchGroups < SCARD_AUTOALLOCATE / sizeof(WCHAR)); const size_t blen = sizeof(WCHAR) * cchGroups; WINPR_ASSERT(blen <= UINT32_MAX); ret.cBytes = (UINT32)blen; @@ -1294,7 +1295,7 @@ static LONG smartcard_StatusW_Call(scard_call_context* smartcard, wStream* out, } /* SCardStatusW returns number of characters, we need number of bytes */ - WINPR_ASSERT(ret.cBytes != SCARD_AUTOALLOCATE); + WINPR_ASSERT(ret.cBytes < SCARD_AUTOALLOCATE / sizeof(WCHAR)); const size_t blen = sizeof(WCHAR) * ret.cBytes; WINPR_ASSERT(blen <= UINT32_MAX); ret.cBytes = (UINT32)blen; From 469f75a3145cab916b160a48daeaff4707ca5cea Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 24 Sep 2024 11:39:31 +0200 Subject: [PATCH 6/6] [codec,ncrush] fix possible overflow --- libfreerdp/codec/ncrush.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/libfreerdp/codec/ncrush.c b/libfreerdp/codec/ncrush.c index 32accc8d0..3d00c944d 100644 --- a/libfreerdp/codec/ncrush.c +++ b/libfreerdp/codec/ncrush.c @@ -2341,7 +2341,7 @@ static int ncrush_hash_table_add(NCRUSH_CONTEXT* ncrush, const BYTE* pSrcData, U return 1; } -static int ncrush_find_match_length(const BYTE* Ptr1, const BYTE* Ptr2, const BYTE* HistoryPtr) +static intptr_t ncrush_find_match_length(const BYTE* Ptr1, const BYTE* Ptr2, const BYTE* HistoryPtr) { BYTE val1 = 0; BYTE val2 = 0; @@ -2360,22 +2360,13 @@ static int ncrush_find_match_length(const BYTE* Ptr1, const BYTE* Ptr2, const BY val2 = *Ptr2++; } while (val1 == val2); - const intptr_t psize = Ptr1 - (Ptr + 1); - WINPR_ASSERT(psize <= INT_MAX); - WINPR_ASSERT(psize >= -INT_MAX); - return (int)psize; + return Ptr1 - (Ptr + 1); } static int ncrush_find_best_match(NCRUSH_CONTEXT* ncrush, UINT16 HistoryOffset, UINT32* pMatchOffset) { int Length = 0; - int MatchLength = 0; - BYTE* MatchPtr = NULL; - UINT16 Offset = 0; - UINT16 NextOffset = 0; - UINT16 MatchOffset = 0; - BYTE* HistoryBuffer = NULL; WINPR_ASSERT(ncrush); WINPR_ASSERT(pMatchOffset); @@ -2383,13 +2374,14 @@ static int ncrush_find_best_match(NCRUSH_CONTEXT* ncrush, UINT16 HistoryOffset, if (!ncrush->MatchTable[HistoryOffset]) return -1; - MatchLength = 2; - Offset = HistoryOffset; - HistoryBuffer = (BYTE*)ncrush->HistoryBuffer; + int MatchLength = 2; + UINT16 Offset = HistoryOffset; + BYTE* HistoryBuffer = (BYTE*)ncrush->HistoryBuffer; + ncrush->MatchTable[0] = HistoryOffset; - MatchOffset = ncrush->MatchTable[HistoryOffset]; - NextOffset = ncrush->MatchTable[Offset]; - MatchPtr = &HistoryBuffer[MatchLength]; + UINT16 MatchOffset = ncrush->MatchTable[HistoryOffset]; + UINT16 NextOffset = ncrush->MatchTable[Offset]; + BYTE* MatchPtr = &HistoryBuffer[MatchLength]; for (int i = 0; i < 4; i++) { @@ -2450,9 +2442,13 @@ static int ncrush_find_best_match(NCRUSH_CONTEXT* ncrush, UINT16 HistoryOffset, if ((Offset != HistoryOffset) && Offset) { - Length = ncrush_find_match_length(&HistoryBuffer[HistoryOffset + 2], - &HistoryBuffer[Offset + 2], ncrush->HistoryPtr) + - 2; + const intptr_t len = + ncrush_find_match_length(&HistoryBuffer[HistoryOffset + 2], + &HistoryBuffer[Offset + 2], ncrush->HistoryPtr); + WINPR_ASSERT(len < INT_MAX - 2); + WINPR_ASSERT(len > INT_MIN + 2); + + Length = (int)len + 2; if (Length < 2) return -1;