From 0445ed6734c70fc94d3900dbb176142c3d6b7f72 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 27 Feb 2026 11:56:23 +0100 Subject: [PATCH] [winpr,pubsub] check return of PubSub_Subscribe --- client/SDL/SDL2/sdl_disp.cpp | 6 ++++-- client/SDL/SDL2/sdl_freerdp.cpp | 9 ++++++--- client/SDL/SDL3/sdl_context.cpp | 9 ++++++--- client/SDL/SDL3/sdl_disp.cpp | 6 ++++-- client/Sample/tf_freerdp.c | 9 ++++++--- client/Wayland/wlf_disp.c | 18 +++++++++--------- client/Wayland/wlfreerdp.c | 9 ++++++--- client/X11/xf_client.c | 16 +++++++++++----- client/X11/xf_disp.c | 20 ++++++++++---------- server/proxy/pf_client.c | 6 ++++-- winpr/libwinpr/utils/test/TestPubSub.c | 6 ++++-- 11 files changed, 70 insertions(+), 44 deletions(-) diff --git a/client/SDL/SDL2/sdl_disp.cpp b/client/SDL/SDL2/sdl_disp.cpp index 6bc51f328..5f9b8332c 100644 --- a/client/SDL/SDL2/sdl_disp.cpp +++ b/client/SDL/SDL2/sdl_disp.cpp @@ -462,8 +462,10 @@ sdlDispContext::sdlDispContext(SdlContext* sdl) : _sdl(sdl) WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth)); _lastSentHeight = _targetHeight = WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)); - PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated); - PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset); + if (PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated) < 0) + throw std::exception(); + if (PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset) < 0) + throw std::exception(); addTimer(); } diff --git a/client/SDL/SDL2/sdl_freerdp.cpp b/client/SDL/SDL2/sdl_freerdp.cpp index 35cb7bb8c..3f9898f05 100644 --- a/client/SDL/SDL2/sdl_freerdp.cpp +++ b/client/SDL/SDL2/sdl_freerdp.cpp @@ -605,9 +605,12 @@ static BOOL sdl_pre_connect(freerdp* instance) * callbacks or deactivate certain features. */ /* Register the channel listeners. * They are required to set up / tear down channels if they are loaded. */ - PubSub_SubscribeChannelConnected(instance->context->pubSub, sdl_OnChannelConnectedEventHandler); - PubSub_SubscribeChannelDisconnected(instance->context->pubSub, - sdl_OnChannelDisconnectedEventHandler); + if (PubSub_SubscribeChannelConnected(instance->context->pubSub, + sdl_OnChannelConnectedEventHandler) < 0) + return FALSE; + if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub, + sdl_OnChannelDisconnectedEventHandler) < 0) + return FALSE; if (!freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly)) { diff --git a/client/SDL/SDL3/sdl_context.cpp b/client/SDL/SDL3/sdl_context.cpp index 4aa8750fd..a731d3a33 100644 --- a/client/SDL/SDL3/sdl_context.cpp +++ b/client/SDL/SDL3/sdl_context.cpp @@ -155,9 +155,12 @@ BOOL SdlContext::preConnect(freerdp* instance) * callbacks or deactivate certain features. */ /* Register the channel listeners. * They are required to set up / tear down channels if they are loaded. */ - PubSub_SubscribeChannelConnected(instance->context->pubSub, sdl_OnChannelConnectedEventHandler); - PubSub_SubscribeChannelDisconnected(instance->context->pubSub, - sdl_OnChannelDisconnectedEventHandler); + if (PubSub_SubscribeChannelConnected(instance->context->pubSub, + sdl_OnChannelConnectedEventHandler) < 0) + return FALSE; + if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub, + sdl_OnChannelDisconnectedEventHandler) < 0) + return FALSE; if (!freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly)) { diff --git a/client/SDL/SDL3/sdl_disp.cpp b/client/SDL/SDL3/sdl_disp.cpp index 2b0684ed9..84671b06b 100644 --- a/client/SDL/SDL3/sdl_disp.cpp +++ b/client/SDL/SDL3/sdl_disp.cpp @@ -470,8 +470,10 @@ sdlDispContext::sdlDispContext(SdlContext* sdl) : _sdl(sdl) auto pubSub = _sdl->context()->pubSub; - PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated); - PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset); + if (PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated) < 0) + throw std::exception(); + if (PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset) < 0) + throw std::exception(); std::ignore = addTimer(); } diff --git a/client/Sample/tf_freerdp.c b/client/Sample/tf_freerdp.c index d8e33d0a7..a42972a25 100644 --- a/client/Sample/tf_freerdp.c +++ b/client/Sample/tf_freerdp.c @@ -167,9 +167,12 @@ static BOOL tf_pre_connect(freerdp* instance) * callbacks or deactivate certain features. */ /* Register the channel listeners. * They are required to set up / tear down channels if they are loaded. */ - PubSub_SubscribeChannelConnected(instance->context->pubSub, tf_OnChannelConnectedEventHandler); - PubSub_SubscribeChannelDisconnected(instance->context->pubSub, - tf_OnChannelDisconnectedEventHandler); + if (PubSub_SubscribeChannelConnected(instance->context->pubSub, + tf_OnChannelConnectedEventHandler) < 0) + return FALSE; + if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub, + tf_OnChannelDisconnectedEventHandler) < 0) + return FALSE; /* TODO: Any code your client requires */ return TRUE; diff --git a/client/Wayland/wlf_disp.c b/client/Wayland/wlf_disp.c index ff92fa576..40a369a23 100644 --- a/client/Wayland/wlf_disp.c +++ b/client/Wayland/wlf_disp.c @@ -271,16 +271,18 @@ static void wlf_disp_OnGraphicsReset(void* context, const GraphicsResetEventArgs wlfDispContext* wlf_disp_new(wlfContext* wlc) { - wlfDispContext* ret = nullptr; - wPubSub* pubSub = nullptr; - rdpSettings* settings = nullptr; - if (!wlc || !wlc->common.context.settings || !wlc->common.context.pubSub) return nullptr; - settings = wlc->common.context.settings; - pubSub = wlc->common.context.pubSub; - ret = calloc(1, sizeof(wlfDispContext)); + rdpSettings* settings = wlc->common.context.settings; + wPubSub* pubSub = wlc->common.context.pubSub; + + if (PubSub_SubscribeActivated(pubSub, wlf_disp_OnActivated) < 0) + return nullptr; + if (PubSub_SubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset) < 0) + return nullptr; + + wlfDispContext* ret = calloc(1, sizeof(wlfDispContext)); if (!ret) return nullptr; @@ -290,8 +292,6 @@ wlfDispContext* wlf_disp_new(wlfContext* wlc) WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth)); ret->lastSentHeight = ret->targetHeight = WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)); - PubSub_SubscribeActivated(pubSub, wlf_disp_OnActivated); - PubSub_SubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset); return ret; } diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c index 3cb8527ad..5aa0508a5 100644 --- a/client/Wayland/wlfreerdp.c +++ b/client/Wayland/wlfreerdp.c @@ -197,9 +197,12 @@ static BOOL wl_pre_connect(freerdp* instance) return FALSE; if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_WAYLAND)) return FALSE; - PubSub_SubscribeChannelConnected(instance->context->pubSub, wlf_OnChannelConnectedEventHandler); - PubSub_SubscribeChannelDisconnected(instance->context->pubSub, - wlf_OnChannelDisconnectedEventHandler); + if (PubSub_SubscribeChannelConnected(instance->context->pubSub, + wlf_OnChannelConnectedEventHandler) < 0) + return FALSE; + if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub, + wlf_OnChannelDisconnectedEventHandler) < 0) + return FALSE; if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen)) { diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index a157d06ee..17d4e21ce 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1178,8 +1178,11 @@ static BOOL xf_pre_connect(freerdp* instance) return FALSE; if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_XSERVER)) return FALSE; - PubSub_SubscribeChannelConnected(context->pubSub, xf_OnChannelConnectedEventHandler); - PubSub_SubscribeChannelDisconnected(context->pubSub, xf_OnChannelDisconnectedEventHandler); + if (PubSub_SubscribeChannelConnected(context->pubSub, xf_OnChannelConnectedEventHandler) < 0) + return FALSE; + if (PubSub_SubscribeChannelDisconnected(context->pubSub, xf_OnChannelDisconnectedEventHandler) < + 0) + return FALSE; if (!freerdp_settings_get_string(settings, FreeRDP_Username) && !freerdp_settings_get_bool(settings, FreeRDP_CredentialsFromStdin) && @@ -2058,10 +2061,13 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context) instance->PostFinalDisconnect = xf_post_final_disconnect; instance->LogonErrorInfo = xf_logon_error_info; instance->GetAccessToken = client_cli_get_access_token; - PubSub_SubscribeTerminate(context->pubSub, xf_TerminateEventHandler); + if (PubSub_SubscribeTerminate(context->pubSub, xf_TerminateEventHandler) < 0) + return FALSE; #ifdef WITH_XRENDER - PubSub_SubscribeZoomingChange(context->pubSub, xf_ZoomingChangeEventHandler); - PubSub_SubscribePanningChange(context->pubSub, xf_PanningChangeEventHandler); + if (PubSub_SubscribeZoomingChange(context->pubSub, xf_ZoomingChangeEventHandler) < 0) + return FALSE; + if (PubSub_SubscribePanningChange(context->pubSub, xf_PanningChangeEventHandler) < 0) + return FALSE; #endif xfc->log = WLog_Get(TAG); diff --git a/client/X11/xf_disp.c b/client/X11/xf_disp.c index 0bfeed842..ede54fd2a 100644 --- a/client/X11/xf_disp.c +++ b/client/X11/xf_disp.c @@ -333,19 +333,22 @@ static void xf_disp_OnWindowStateChange(void* context, const WindowStateChangeEv xfDispContext* xf_disp_new(xfContext* xfc) { - xfDispContext* ret = nullptr; - const rdpSettings* settings = nullptr; - wPubSub* pubSub = nullptr; - WINPR_ASSERT(xfc); - pubSub = xfc->common.context.pubSub; + wPubSub* pubSub = xfc->common.context.pubSub; WINPR_ASSERT(pubSub); - settings = xfc->common.context.settings; + const rdpSettings* settings = xfc->common.context.settings; WINPR_ASSERT(settings); - ret = calloc(1, sizeof(xfDispContext)); + if (PubSub_SubscribeActivated(pubSub, xf_disp_OnActivated) < 0) + return nullptr; + if (PubSub_SubscribeGraphicsReset(pubSub, xf_disp_OnGraphicsReset) < 0) + return nullptr; + if (PubSub_SubscribeWindowStateChange(pubSub, xf_disp_OnWindowStateChange) < 0) + return nullptr; + + xfDispContext* ret = calloc(1, sizeof(xfDispContext)); if (!ret) return nullptr; @@ -363,9 +366,6 @@ xfDispContext* xf_disp_new(xfContext* xfc) freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth); ret->lastSentHeight = ret->targetHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight); - PubSub_SubscribeActivated(pubSub, xf_disp_OnActivated); - PubSub_SubscribeGraphicsReset(pubSub, xf_disp_OnGraphicsReset); - PubSub_SubscribeWindowStateChange(pubSub, xf_disp_OnWindowStateChange); return ret; } diff --git a/server/proxy/pf_client.c b/server/proxy/pf_client.c index 51b95db56..d0c157208 100644 --- a/server/proxy/pf_client.c +++ b/server/proxy/pf_client.c @@ -289,8 +289,10 @@ static BOOL pf_client_pre_connect(freerdp* instance) if (!freerdp_settings_set_bool(settings, FreeRDP_AutoReconnectionEnabled, TRUE)) return FALSE; - PubSub_SubscribeErrorInfo(instance->context->pubSub, pf_client_on_error_info); - PubSub_SubscribeActivated(instance->context->pubSub, pf_client_on_activated); + if (PubSub_SubscribeErrorInfo(instance->context->pubSub, pf_client_on_error_info) < 0) + return FALSE; + if (PubSub_SubscribeActivated(instance->context->pubSub, pf_client_on_activated) < 0) + return FALSE; if (!pf_client_use_peer_load_balance_info(pc)) return FALSE; diff --git a/winpr/libwinpr/utils/test/TestPubSub.c b/winpr/libwinpr/utils/test/TestPubSub.c index 50693cd1e..39ef0e01f 100644 --- a/winpr/libwinpr/utils/test/TestPubSub.c +++ b/winpr/libwinpr/utils/test/TestPubSub.c @@ -43,8 +43,10 @@ int TestPubSub(int argc, char* argv[]) PubSub_AddEventTypes(node, Node_Events, NODE_EVENT_COUNT); - PubSub_SubscribeMouseMotion(node, MouseMotionEventHandler); - PubSub_SubscribeMouseButton(node, MouseButtonEventHandler); + if (PubSub_SubscribeMouseMotion(node, MouseMotionEventHandler) < 0) + return -1; + if (PubSub_SubscribeMouseButton(node, MouseButtonEventHandler) < 0) + return -1; /* Call Event Handler */ {