From 674fae5ce6e9dba44fb6f0c71d59ad8aff082437 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 20 Dec 2017 14:52:28 +0100 Subject: [PATCH 1/8] Refactored function visibility. --- channels/rail/client/rail_orders.c | 50 ++++++++++++++++++++++-------- channels/rail/client/rail_orders.h | 19 +----------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/channels/rail/client/rail_orders.c b/channels/rail/client/rail_orders.c index b38f9ca3c..6492d2c3b 100644 --- a/channels/rail/client/rail_orders.c +++ b/channels/rail/client/rail_orders.c @@ -32,6 +32,28 @@ #include "rail_orders.h" +static UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* exec_result); +static UINT rail_read_server_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam); +static UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo); +static UINT rail_read_server_localmovesize_order(wStream* s, + RAIL_LOCALMOVESIZE_ORDER* localmovesize); +static UINT rail_read_server_get_appid_resp_order(wStream* s, + RAIL_GET_APPID_RESP_ORDER* get_appid_resp); +static UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); + +static void rail_write_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* client_status); +static UINT rail_write_client_exec_order(wStream* s, RAIL_EXEC_ORDER* exec); +static void rail_write_client_activate_order(wStream* s, RAIL_ACTIVATE_ORDER* activate); +static void rail_write_client_sysmenu_order(wStream* s, RAIL_SYSMENU_ORDER* sysmenu); +static void rail_write_client_syscommand_order(wStream* s, RAIL_SYSCOMMAND_ORDER* syscommand); +static void rail_write_client_notify_event_order(wStream* s, RAIL_NOTIFY_EVENT_ORDER* notify_event); +static void rail_write_client_window_move_order(wStream* s, RAIL_WINDOW_MOVE_ORDER* window_move); +static void rail_write_client_get_appid_req_order(wStream* s, + RAIL_GET_APPID_REQ_ORDER* get_appid_req); +static void rail_write_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); + +static UINT rail_send_client_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam); +static UINT rail_send_client_sysparams_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam); /** * Function description @@ -94,7 +116,7 @@ UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType) * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_write_high_contrast(wStream* s, RAIL_HIGH_CONTRAST* highContrast) +static UINT rail_write_high_contrast(wStream* s, RAIL_HIGH_CONTRAST* highContrast) { highContrast->colorSchemeLength = highContrast->colorScheme.length + 2; Stream_Write_UINT32(s, highContrast->flags); /* flags (4 bytes) */ @@ -396,7 +418,7 @@ void rail_write_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarI * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_recv_handshake_order(railPlugin* rail, RAIL_HANDSHAKE_ORDER* handshake, wStream* s) +static UINT rail_recv_handshake_order(railPlugin* rail, RAIL_HANDSHAKE_ORDER* handshake, wStream* s) { RailClientContext* context = rail_get_client_interface(rail); UINT error; @@ -423,8 +445,8 @@ UINT rail_recv_handshake_order(railPlugin* rail, RAIL_HANDSHAKE_ORDER* handshake * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_recv_handshake_ex_order(railPlugin* rail, RAIL_HANDSHAKE_EX_ORDER* handshakeEx, - wStream* s) +static UINT rail_recv_handshake_ex_order(railPlugin* rail, RAIL_HANDSHAKE_EX_ORDER* handshakeEx, + wStream* s) { RailClientContext* context = rail_get_client_interface(rail); UINT error; @@ -451,7 +473,8 @@ UINT rail_recv_handshake_ex_order(railPlugin* rail, RAIL_HANDSHAKE_EX_ORDER* han * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_recv_exec_result_order(railPlugin* rail, RAIL_EXEC_RESULT_ORDER* execResult, wStream* s) +static UINT rail_recv_exec_result_order(railPlugin* rail, RAIL_EXEC_RESULT_ORDER* execResult, + wStream* s) { RailClientContext* context = rail_get_client_interface(rail); UINT error; @@ -479,7 +502,8 @@ UINT rail_recv_exec_result_order(railPlugin* rail, RAIL_EXEC_RESULT_ORDER* execR * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_recv_server_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam, wStream* s) +static UINT rail_recv_server_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam, + wStream* s) { RailClientContext* context = rail_get_client_interface(rail); UINT error; @@ -506,8 +530,8 @@ UINT rail_recv_server_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysp * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_recv_server_minmaxinfo_order(railPlugin* rail, RAIL_MINMAXINFO_ORDER* minMaxInfo, - wStream* s) +static UINT rail_recv_server_minmaxinfo_order(railPlugin* rail, RAIL_MINMAXINFO_ORDER* minMaxInfo, + wStream* s) { RailClientContext* context = rail_get_client_interface(rail); UINT error; @@ -534,7 +558,8 @@ UINT rail_recv_server_minmaxinfo_order(railPlugin* rail, RAIL_MINMAXINFO_ORDER* * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_recv_server_localmovesize_order(railPlugin* rail, RAIL_LOCALMOVESIZE_ORDER* localMoveSize, +static UINT rail_recv_server_localmovesize_order(railPlugin* rail, + RAIL_LOCALMOVESIZE_ORDER* localMoveSize, wStream* s) { RailClientContext* context = rail_get_client_interface(rail); @@ -562,7 +587,7 @@ UINT rail_recv_server_localmovesize_order(railPlugin* rail, RAIL_LOCALMOVESIZE_O * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_recv_server_get_appid_resp_order(railPlugin* rail, +static UINT rail_recv_server_get_appid_resp_order(railPlugin* rail, RAIL_GET_APPID_RESP_ORDER* getAppIdResp, wStream* s) { RailClientContext* context = rail_get_client_interface(rail); @@ -590,8 +615,8 @@ UINT rail_recv_server_get_appid_resp_order(railPlugin* rail, * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_recv_langbar_info_order(railPlugin* rail, RAIL_LANGBAR_INFO_ORDER* langBarInfo, - wStream* s) +static UINT rail_recv_langbar_info_order(railPlugin* rail, RAIL_LANGBAR_INFO_ORDER* langBarInfo, + wStream* s) { RailClientContext* context = rail_get_client_interface(rail); UINT error; @@ -688,7 +713,6 @@ UINT rail_order_recv(railPlugin* rail, wStream* s) default: WLog_ERR(TAG, "Unknown RAIL PDU order reveived."); return ERROR_INVALID_DATA; - break; } return CHANNEL_RC_OK; diff --git a/channels/rail/client/rail_orders.h b/channels/rail/client/rail_orders.h index dab414b08..028286aa1 100644 --- a/channels/rail/client/rail_orders.h +++ b/channels/rail/client/rail_orders.h @@ -29,23 +29,7 @@ #define TAG CHANNELS_TAG("rail.client") -UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* exec_result); -UINT rail_read_server_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam); -UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo); -UINT rail_read_server_localmovesize_order(wStream* s, RAIL_LOCALMOVESIZE_ORDER* localmovesize); -UINT rail_read_server_get_appid_resp_order(wStream* s, RAIL_GET_APPID_RESP_ORDER* get_appid_resp); -UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); - -void rail_write_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* client_status); -UINT rail_write_client_exec_order(wStream* s, RAIL_EXEC_ORDER* exec); UINT rail_write_client_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam); -void rail_write_client_activate_order(wStream* s, RAIL_ACTIVATE_ORDER* activate); -void rail_write_client_sysmenu_order(wStream* s, RAIL_SYSMENU_ORDER* sysmenu); -void rail_write_client_syscommand_order(wStream* s, RAIL_SYSCOMMAND_ORDER* syscommand); -void rail_write_client_notify_event_order(wStream* s, RAIL_NOTIFY_EVENT_ORDER* notify_event); -void rail_write_client_window_move_order(wStream* s, RAIL_WINDOW_MOVE_ORDER* window_move); -void rail_write_client_get_appid_req_order(wStream* s, RAIL_GET_APPID_REQ_ORDER* get_appid_req); -void rail_write_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); UINT rail_order_recv(railPlugin* rail, wStream* s); UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType); @@ -54,11 +38,10 @@ UINT rail_send_handshake_order(railPlugin* rail, RAIL_HANDSHAKE_ORDER* handshake UINT rail_send_handshake_ex_order(railPlugin* rail, RAIL_HANDSHAKE_EX_ORDER* handshakeEx); UINT rail_send_client_status_order(railPlugin* rail, RAIL_CLIENT_STATUS_ORDER* clientStatus); UINT rail_send_client_exec_order(railPlugin* rail, RAIL_EXEC_ORDER* exec); -UINT rail_send_client_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam); -UINT rail_send_client_sysparams_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam); UINT rail_send_client_activate_order(railPlugin* rail, RAIL_ACTIVATE_ORDER* activate); UINT rail_send_client_sysmenu_order(railPlugin* rail, RAIL_SYSMENU_ORDER* sysmenu); UINT rail_send_client_syscommand_order(railPlugin* rail, RAIL_SYSCOMMAND_ORDER* syscommand); + UINT rail_send_client_notify_event_order(railPlugin* rail, RAIL_NOTIFY_EVENT_ORDER* notifyEvent); UINT rail_send_client_window_move_order(railPlugin* rail, RAIL_WINDOW_MOVE_ORDER* windowMove); UINT rail_send_client_get_appid_req_order(railPlugin* rail, RAIL_GET_APPID_REQ_ORDER* getAppIdReq); From 4dd0ccd70304dbac10a0c8a485017aa414965f72 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 20 Dec 2017 15:00:21 +0100 Subject: [PATCH 2/8] Added argument checks. --- channels/rail/client/rail_main.c | 156 +++++++++++++---- channels/rail/client/rail_orders.c | 268 ++++++++++++++++++++++------- channels/rail/rail_common.c | 11 +- 3 files changed, 337 insertions(+), 98 deletions(-) diff --git a/channels/rail/client/rail_main.c b/channels/rail/client/rail_main.c index ad93430c4..1f3ac9c93 100644 --- a/channels/rail/client/rail_main.c +++ b/channels/rail/client/rail_main.c @@ -38,6 +38,10 @@ RailClientContext* rail_get_client_interface(railPlugin* rail) { RailClientContext* pInterface; + + if (!rail) + return NULL; + pInterface = (RailClientContext*) rail->channelEntryPoints.pInterface; return pInterface; } @@ -52,14 +56,10 @@ static UINT rail_send(railPlugin* rail, wStream* s) UINT status; if (!rail) - { - status = CHANNEL_RC_BAD_INIT_HANDLE; - } - else - { - status = rail->channelEntryPoints.pVirtualChannelWriteEx(rail->InitHandle, rail->OpenHandle, - Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s); - } + return CHANNEL_RC_BAD_INIT_HANDLE; + + status = rail->channelEntryPoints.pVirtualChannelWriteEx(rail->InitHandle, rail->OpenHandle, + Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s); if (status != CHANNEL_RC_OK) { @@ -79,6 +79,10 @@ static UINT rail_send(railPlugin* rail, wStream* s) UINT rail_send_channel_data(railPlugin* rail, void* data, size_t length) { wStream* s = NULL; + + if (!rail || !data) + return ERROR_INVALID_PARAMETER; + s = Stream_New(NULL, length); if (!s) @@ -97,17 +101,15 @@ UINT rail_send_channel_data(railPlugin* rail, void* data, size_t length) */ static void rail_client_clean_exec_order(RAIL_EXEC_ORDER* exec) { - if (!exec) - return; + if (!exec) + return; - free(exec->exeOrFile.string); - exec->exeOrFile.string = NULL; - - free(exec->workingDir.string); - exec->workingDir.string = NULL; - - free(exec->arguments.string); - exec->arguments.string = NULL; + free(exec->exeOrFile.string); + exec->exeOrFile.string = NULL; + free(exec->workingDir.string); + exec->workingDir.string = NULL; + free(exec->arguments.string); + exec->arguments.string = NULL; } /** @@ -124,13 +126,18 @@ static UINT rail_client_execute(RailClientContext* context, { char* exeOrFile; UINT error; - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !exec) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; exeOrFile = exec->RemoteApplicationProgram; if (!exeOrFile) return ERROR_INVALID_PARAMETER; - if (strlen(exeOrFile) >= 2) + if (strnlen(exeOrFile, MAX_PATH) >= 2) { if (strncmp(exeOrFile, "||", 2) != 0) exec->flags |= RAIL_EXEC_FLAG_FILE; @@ -155,7 +162,12 @@ static UINT rail_client_execute(RailClientContext* context, static UINT rail_client_activate(RailClientContext* context, RAIL_ACTIVATE_ORDER* activate) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !activate) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_client_activate_order(rail, activate); } @@ -168,10 +180,14 @@ static UINT rail_send_client_sysparam(RailClientContext* context, RAIL_SYSPARAM_ORDER* sysparam) { wStream* s; - int length; - railPlugin* rail = (railPlugin*) context->handle; + size_t length = RAIL_SYSPARAM_ORDER_LENGTH; + railPlugin* rail; UINT error; - length = RAIL_SYSPARAM_ORDER_LENGTH; + + if (!context || !sysparam) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; switch (sysparam->param) { @@ -231,6 +247,9 @@ static UINT rail_client_system_param(RailClientContext* context, { UINT error = CHANNEL_RC_OK; + if (!context || !sysparam) + return ERROR_INVALID_PARAMETER; + if (sysparam->params & SPI_MASK_SET_HIGH_CONTRAST) { sysparam->param = SPI_SET_HIGH_CONTRAST; @@ -319,6 +338,9 @@ static UINT rail_client_system_param(RailClientContext* context, static UINT rail_server_system_param(RailClientContext* context, RAIL_SYSPARAM_ORDER* sysparam) { + if (!context || !sysparam) + return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_OK; /* stub - should be registered by client */ } @@ -330,7 +352,12 @@ static UINT rail_server_system_param(RailClientContext* context, static UINT rail_client_system_command(RailClientContext* context, RAIL_SYSCOMMAND_ORDER* syscommand) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !syscommand) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_client_syscommand_order(rail, syscommand); } @@ -342,7 +369,12 @@ static UINT rail_client_system_command(RailClientContext* context, static UINT rail_client_handshake(RailClientContext* context, RAIL_HANDSHAKE_ORDER* handshake) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !handshake) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_handshake_order(rail, handshake); } @@ -354,6 +386,9 @@ static UINT rail_client_handshake(RailClientContext* context, static UINT rail_server_handshake(RailClientContext* context, RAIL_HANDSHAKE_ORDER* handshake) { + if (!context || !handshake) + return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_OK; /* stub - should be registered by client */ } @@ -365,7 +400,12 @@ static UINT rail_server_handshake(RailClientContext* context, static UINT rail_client_handshake_ex(RailClientContext* context, RAIL_HANDSHAKE_EX_ORDER* handshakeEx) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !handshakeEx) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_handshake_ex_order(rail, handshakeEx); } @@ -377,6 +417,9 @@ static UINT rail_client_handshake_ex(RailClientContext* context, static UINT rail_server_handshake_ex(RailClientContext* context, RAIL_HANDSHAKE_EX_ORDER* handshakeEx) { + if (!context || !handshakeEx) + return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_OK; /* stub - should be registered by client */ } @@ -388,7 +431,12 @@ static UINT rail_server_handshake_ex(RailClientContext* context, static UINT rail_client_notify_event(RailClientContext* context, RAIL_NOTIFY_EVENT_ORDER* notifyEvent) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !notifyEvent) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_client_notify_event_order(rail, notifyEvent); } @@ -400,7 +448,12 @@ static UINT rail_client_notify_event(RailClientContext* context, static UINT rail_client_window_move(RailClientContext* context, RAIL_WINDOW_MOVE_ORDER* windowMove) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !windowMove) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_client_window_move_order(rail, windowMove); } @@ -412,6 +465,9 @@ static UINT rail_client_window_move(RailClientContext* context, static UINT rail_server_local_move_size(RailClientContext* context, RAIL_LOCALMOVESIZE_ORDER* localMoveSize) { + if (!context || !localMoveSize) + return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_OK; /* stub - should be registered by client */ } @@ -423,6 +479,9 @@ static UINT rail_server_local_move_size(RailClientContext* context, static UINT rail_server_min_max_info(RailClientContext* context, RAIL_MINMAXINFO_ORDER* minMaxInfo) { + if (!context || !minMaxInfo) + return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_OK; /* stub - should be registered by client */ } @@ -434,7 +493,12 @@ static UINT rail_server_min_max_info(RailClientContext* context, static UINT rail_client_information(RailClientContext* context, RAIL_CLIENT_STATUS_ORDER* clientStatus) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !clientStatus) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_client_status_order(rail, clientStatus); } @@ -446,7 +510,12 @@ static UINT rail_client_information(RailClientContext* context, static UINT rail_client_system_menu(RailClientContext* context, RAIL_SYSMENU_ORDER* sysmenu) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !sysmenu) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_client_sysmenu_order(rail, sysmenu); } @@ -458,7 +527,12 @@ static UINT rail_client_system_menu(RailClientContext* context, static UINT rail_client_language_bar_info(RailClientContext* context, RAIL_LANGBAR_INFO_ORDER* langBarInfo) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !langBarInfo) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_client_langbar_info_order(rail, langBarInfo); } @@ -470,6 +544,9 @@ static UINT rail_client_language_bar_info(RailClientContext* context, static UINT rail_server_language_bar_info(RailClientContext* context, RAIL_LANGBAR_INFO_ORDER* langBarInfo) { + if (!context || !langBarInfo) + return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_OK; /* stub - should be registered by client */ } @@ -481,6 +558,9 @@ static UINT rail_server_language_bar_info(RailClientContext* context, static UINT rail_server_execute_result(RailClientContext* context, RAIL_EXEC_RESULT_ORDER* execResult) { + if (!context || !execResult) + return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_OK; /* stub - should be registered by client */ } @@ -492,7 +572,12 @@ static UINT rail_server_execute_result(RailClientContext* context, static UINT rail_client_get_appid_request(RailClientContext* context, RAIL_GET_APPID_REQ_ORDER* getAppIdReq) { - railPlugin* rail = (railPlugin*) context->handle; + railPlugin* rail; + + if (!context || !getAppIdReq || !context->handle) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*) context->handle; return rail_send_client_get_appid_req_order(rail, getAppIdReq); } @@ -504,6 +589,9 @@ static UINT rail_client_get_appid_request(RailClientContext* context, static UINT rail_server_get_appid_response(RailClientContext* context, RAIL_GET_APPID_RESP_ORDER* getAppIdResp) { + if (!context || !getAppIdResp) + return ERROR_INVALID_PARAMETER; + return CHANNEL_RC_OK; /* stub - should be registered by client */ } @@ -635,9 +723,9 @@ static void* rail_virtual_channel_client_thread(void* arg) if (message.id == 0) { data = (wStream*) message.wParam; - error = rail_order_recv(rail, data); Stream_Free(data, TRUE); + if (error) { WLog_ERR(TAG, "rail_order_recv failed with error %"PRIu32"!", error); diff --git a/channels/rail/client/rail_orders.c b/channels/rail/client/rail_orders.c index 6492d2c3b..7e489e3ab 100644 --- a/channels/rail/client/rail_orders.c +++ b/channels/rail/client/rail_orders.c @@ -32,29 +32,6 @@ #include "rail_orders.h" -static UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* exec_result); -static UINT rail_read_server_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam); -static UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo); -static UINT rail_read_server_localmovesize_order(wStream* s, - RAIL_LOCALMOVESIZE_ORDER* localmovesize); -static UINT rail_read_server_get_appid_resp_order(wStream* s, - RAIL_GET_APPID_RESP_ORDER* get_appid_resp); -static UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); - -static void rail_write_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* client_status); -static UINT rail_write_client_exec_order(wStream* s, RAIL_EXEC_ORDER* exec); -static void rail_write_client_activate_order(wStream* s, RAIL_ACTIVATE_ORDER* activate); -static void rail_write_client_sysmenu_order(wStream* s, RAIL_SYSMENU_ORDER* sysmenu); -static void rail_write_client_syscommand_order(wStream* s, RAIL_SYSCOMMAND_ORDER* syscommand); -static void rail_write_client_notify_event_order(wStream* s, RAIL_NOTIFY_EVENT_ORDER* notify_event); -static void rail_write_client_window_move_order(wStream* s, RAIL_WINDOW_MOVE_ORDER* window_move); -static void rail_write_client_get_appid_req_order(wStream* s, - RAIL_GET_APPID_REQ_ORDER* get_appid_req); -static void rail_write_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); - -static UINT rail_send_client_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam); -static UINT rail_send_client_sysparams_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam); - /** * Function description * @@ -62,6 +39,9 @@ static UINT rail_send_client_sysparams_order(railPlugin* rail, RAIL_SYSPARAM_ORD */ static UINT rail_write_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string) { + if (!s || !unicode_string) + return ERROR_INVALID_PARAMETER; + if (!Stream_EnsureRemainingCapacity(s, 2 + unicode_string->length)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); @@ -80,6 +60,9 @@ static UINT rail_write_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_s */ static UINT rail_write_unicode_string_value(wStream* s, RAIL_UNICODE_STRING* unicode_string) { + if (!s || !unicode_string) + return ERROR_INVALID_PARAMETER; + if (unicode_string->length > 0) { if (!Stream_EnsureRemainingCapacity(s, unicode_string->length)) @@ -102,6 +85,10 @@ static UINT rail_write_unicode_string_value(wStream* s, RAIL_UNICODE_STRING* uni UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType) { UINT16 orderLength; + + if (!rail || !s) + return ERROR_INVALID_PARAMETER; + orderLength = (UINT16) Stream_GetPosition(s); Stream_SetPosition(s, 0); rail_write_pdu_header(s, orderType, orderLength); @@ -118,6 +105,9 @@ UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType) */ static UINT rail_write_high_contrast(wStream* s, RAIL_HIGH_CONTRAST* highContrast) { + if (!s || !highContrast) + return ERROR_INVALID_PARAMETER; + highContrast->colorSchemeLength = highContrast->colorScheme.length + 2; Stream_Write_UINT32(s, highContrast->flags); /* flags (4 bytes) */ Stream_Write_UINT32(s, highContrast->colorSchemeLength); /* colorSchemeLength (4 bytes) */ @@ -129,8 +119,11 @@ static UINT rail_write_high_contrast(wStream* s, RAIL_HIGH_CONTRAST* highContras * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* execResult) +static UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* execResult) { + if (!s || !execResult) + return ERROR_INVALID_PARAMETER; + if (Stream_GetRemainingLength(s) < 8) { WLog_ERR(TAG, "Stream_GetRemainingLength failed!"); @@ -150,10 +143,13 @@ UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* exec * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_read_server_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam) +static UINT rail_read_server_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam) { BYTE body; + if (!s || !sysparam) + return ERROR_INVALID_PARAMETER; + if (Stream_GetRemainingLength(s) < 5) { WLog_ERR(TAG, "Stream_GetRemainingLength failed!"); @@ -185,8 +181,11 @@ UINT rail_read_server_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam) * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo) +static UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo) { + if (!s || !minmaxinfo) + return ERROR_INVALID_PARAMETER; + if (Stream_GetRemainingLength(s) < 20) { WLog_ERR(TAG, "Stream_GetRemainingLength failed!"); @@ -210,10 +209,14 @@ UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmax * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_read_server_localmovesize_order(wStream* s, RAIL_LOCALMOVESIZE_ORDER* localMoveSize) +static UINT rail_read_server_localmovesize_order(wStream* s, + RAIL_LOCALMOVESIZE_ORDER* localMoveSize) { UINT16 isMoveSizeStart; + if (!s || !localMoveSize) + return ERROR_INVALID_PARAMETER; + if (Stream_GetRemainingLength(s) < 12) { WLog_ERR(TAG, "Stream_GetRemainingLength failed!"); @@ -234,8 +237,12 @@ UINT rail_read_server_localmovesize_order(wStream* s, RAIL_LOCALMOVESIZE_ORDER* * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_read_server_get_appid_resp_order(wStream* s, RAIL_GET_APPID_RESP_ORDER* getAppidResp) +static UINT rail_read_server_get_appid_resp_order(wStream* s, + RAIL_GET_APPID_RESP_ORDER* getAppidResp) { + if (!s || !getAppidResp) + return ERROR_INVALID_PARAMETER; + if (Stream_GetRemainingLength(s) < 516) { WLog_ERR(TAG, "Stream_GetRemainingLength failed!"); @@ -253,8 +260,11 @@ UINT rail_read_server_get_appid_resp_order(wStream* s, RAIL_GET_APPID_RESP_ORDER * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarInfo) +static UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarInfo) { + if (!s || !langbarInfo) + return ERROR_INVALID_PARAMETER; + if (Stream_GetRemainingLength(s) < 4) { WLog_ERR(TAG, "Stream_GetRemainingLength failed!"); @@ -265,9 +275,13 @@ UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarIn return CHANNEL_RC_OK; } -void rail_write_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* clientStatus) +static UINT rail_write_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* clientStatus) { + if (!s || !clientStatus) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, clientStatus->flags); /* flags (4 bytes) */ + return ERROR_SUCCESS; } /** @@ -275,9 +289,13 @@ void rail_write_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* client * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_write_client_exec_order(wStream* s, RAIL_EXEC_ORDER* exec) +static UINT rail_write_client_exec_order(wStream* s, RAIL_EXEC_ORDER* exec) { UINT error; + + if (!s || !exec) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT16(s, exec->flags); /* flags (2 bytes) */ Stream_Write_UINT16(s, exec->exeOrFile.length); /* exeOrFileLength (2 bytes) */ Stream_Write_UINT16(s, exec->workingDir.length); /* workingDirLength (2 bytes) */ @@ -313,6 +331,10 @@ UINT rail_write_client_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam) { BYTE body; UINT error = CHANNEL_RC_OK; + + if (!s || !sysparam) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, sysparam->param); /* systemParam (4 bytes) */ switch (sysparam->param) @@ -366,51 +388,80 @@ UINT rail_write_client_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam) return error; } -void rail_write_client_activate_order(wStream* s, RAIL_ACTIVATE_ORDER* activate) +static UINT rail_write_client_activate_order(wStream* s, RAIL_ACTIVATE_ORDER* activate) { BYTE enabled; + + if (!s || !activate) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, activate->windowId); /* windowId (4 bytes) */ enabled = activate->enabled; Stream_Write_UINT8(s, enabled); /* enabled (1 byte) */ + return ERROR_SUCCESS; } -void rail_write_client_sysmenu_order(wStream* s, RAIL_SYSMENU_ORDER* sysmenu) +static UINT rail_write_client_sysmenu_order(wStream* s, RAIL_SYSMENU_ORDER* sysmenu) { + if (!s || !sysmenu) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, sysmenu->windowId); /* windowId (4 bytes) */ Stream_Write_UINT16(s, sysmenu->left); /* left (2 bytes) */ Stream_Write_UINT16(s, sysmenu->top); /* top (2 bytes) */ + return ERROR_SUCCESS; } -void rail_write_client_syscommand_order(wStream* s, RAIL_SYSCOMMAND_ORDER* syscommand) +static UINT rail_write_client_syscommand_order(wStream* s, RAIL_SYSCOMMAND_ORDER* syscommand) { + if (!s || !syscommand) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, syscommand->windowId); /* windowId (4 bytes) */ Stream_Write_UINT16(s, syscommand->command); /* command (2 bytes) */ + return ERROR_SUCCESS; } -void rail_write_client_notify_event_order(wStream* s, RAIL_NOTIFY_EVENT_ORDER* notifyEvent) +static UINT rail_write_client_notify_event_order(wStream* s, RAIL_NOTIFY_EVENT_ORDER* notifyEvent) { + if (!s || !notifyEvent) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, notifyEvent->windowId); /* windowId (4 bytes) */ Stream_Write_UINT32(s, notifyEvent->notifyIconId); /* notifyIconId (4 bytes) */ Stream_Write_UINT32(s, notifyEvent->message); /* notifyIconId (4 bytes) */ + return ERROR_SUCCESS; } -void rail_write_client_window_move_order(wStream* s, RAIL_WINDOW_MOVE_ORDER* windowMove) +static UINT rail_write_client_window_move_order(wStream* s, RAIL_WINDOW_MOVE_ORDER* windowMove) { + if (!s || !windowMove) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, windowMove->windowId); /* windowId (4 bytes) */ Stream_Write_UINT16(s, windowMove->left); /* left (2 bytes) */ Stream_Write_UINT16(s, windowMove->top); /* top (2 bytes) */ Stream_Write_UINT16(s, windowMove->right); /* right (2 bytes) */ Stream_Write_UINT16(s, windowMove->bottom); /* bottom (2 bytes) */ + return ERROR_SUCCESS; } -void rail_write_client_get_appid_req_order(wStream* s, RAIL_GET_APPID_REQ_ORDER* getAppidReq) +static UINT rail_write_client_get_appid_req_order(wStream* s, RAIL_GET_APPID_REQ_ORDER* getAppidReq) { + if (!s || !getAppidReq) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, getAppidReq->windowId); /* windowId (4 bytes) */ + return ERROR_SUCCESS; } -void rail_write_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarInfo) +static UINT rail_write_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarInfo) { + if (!s || !langbarInfo) + return ERROR_INVALID_PARAMETER; + Stream_Write_UINT32(s, langbarInfo->languageBarStatus); /* languageBarStatus (4 bytes) */ + return ERROR_SUCCESS; } /** @@ -423,6 +474,9 @@ static UINT rail_recv_handshake_order(railPlugin* rail, RAIL_HANDSHAKE_ORDER* ha RailClientContext* context = rail_get_client_interface(rail); UINT error; + if (!context || !handshake || !s) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_handshake_order(s, handshake))) { WLog_ERR(TAG, "rail_read_handshake_order failed with error %"PRIu32"!", error); @@ -451,6 +505,9 @@ static UINT rail_recv_handshake_ex_order(railPlugin* rail, RAIL_HANDSHAKE_EX_ORD RailClientContext* context = rail_get_client_interface(rail); UINT error; + if (!context || !handshakeEx || !s) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_handshake_ex_order(s, handshakeEx))) { WLog_ERR(TAG, "rail_read_handshake_ex_order failed with error %"PRIu32"!", error); @@ -478,6 +535,10 @@ static UINT rail_recv_exec_result_order(railPlugin* rail, RAIL_EXEC_RESULT_ORDER { RailClientContext* context = rail_get_client_interface(rail); UINT error; + + if (!context || !execResult || !s) + return ERROR_INVALID_PARAMETER; + ZeroMemory(execResult, sizeof(RAIL_EXEC_RESULT_ORDER)); if ((error = rail_read_server_exec_result_order(s, execResult))) @@ -508,6 +569,9 @@ static UINT rail_recv_server_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDE RailClientContext* context = rail_get_client_interface(rail); UINT error; + if (!context || !sysparam || !s) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_server_sysparam_order(s, sysparam))) { WLog_ERR(TAG, "rail_read_server_sysparam_order failed with error %"PRIu32"!", error); @@ -536,6 +600,9 @@ static UINT rail_recv_server_minmaxinfo_order(railPlugin* rail, RAIL_MINMAXINFO_ RailClientContext* context = rail_get_client_interface(rail); UINT error; + if (!context || !minMaxInfo || !s) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_server_minmaxinfo_order(s, minMaxInfo))) { WLog_ERR(TAG, "rail_read_server_minmaxinfo_order failed with error %"PRIu32"!", error); @@ -565,6 +632,9 @@ static UINT rail_recv_server_localmovesize_order(railPlugin* rail, RailClientContext* context = rail_get_client_interface(rail); UINT error; + if (!context || !localMoveSize || !s) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_server_localmovesize_order(s, localMoveSize))) { WLog_ERR(TAG, "rail_read_server_localmovesize_order failed with error %"PRIu32"!", error); @@ -593,6 +663,9 @@ static UINT rail_recv_server_get_appid_resp_order(railPlugin* rail, RailClientContext* context = rail_get_client_interface(rail); UINT error; + if (!context || !getAppIdResp || !s) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_server_get_appid_resp_order(s, getAppIdResp))) { WLog_ERR(TAG, "rail_read_server_get_appid_resp_order failed with error %"PRIu32"!", error); @@ -621,6 +694,9 @@ static UINT rail_recv_langbar_info_order(railPlugin* rail, RAIL_LANGBAR_INFO_ORD RailClientContext* context = rail_get_client_interface(rail); UINT error; + if (!context || !langBarInfo) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_langbar_info_order(s, langBarInfo))) { WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %"PRIu32"!", error); @@ -649,6 +725,9 @@ UINT rail_order_recv(railPlugin* rail, wStream* s) UINT16 orderLength; UINT error; + if (!rail || !s) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_pdu_header(s, &orderType, &orderLength))) { WLog_ERR(TAG, "rail_read_pdu_header failed with error %"PRIu32"!", error); @@ -727,6 +806,10 @@ UINT rail_send_handshake_order(railPlugin* rail, RAIL_HANDSHAKE_ORDER* handshake { wStream* s; UINT error; + + if (!rail || !handshake) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_HANDSHAKE_ORDER_LENGTH); if (!s) @@ -750,6 +833,10 @@ UINT rail_send_handshake_ex_order(railPlugin* rail, RAIL_HANDSHAKE_EX_ORDER* han { wStream* s; UINT error; + + if (!rail || !handshakeEx) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_HANDSHAKE_EX_ORDER_LENGTH); if (!s) @@ -773,6 +860,10 @@ UINT rail_send_client_status_order(railPlugin* rail, RAIL_CLIENT_STATUS_ORDER* c { wStream* s; UINT error; + + if (!rail || !clientStatus) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_CLIENT_STATUS_ORDER_LENGTH); if (!s) @@ -781,8 +872,11 @@ UINT rail_send_client_status_order(railPlugin* rail, RAIL_CLIENT_STATUS_ORDER* c return CHANNEL_RC_NO_MEMORY; } - rail_write_client_status_order(s, clientStatus); - error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_CLIENTSTATUS); + error = rail_write_client_status_order(s, clientStatus); + + if (error == ERROR_SUCCESS) + error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_CLIENTSTATUS); + Stream_Free(s, TRUE); return error; } @@ -797,6 +891,10 @@ UINT rail_send_client_exec_order(railPlugin* rail, RAIL_EXEC_ORDER* exec) wStream* s; UINT error; size_t length; + + if (!rail || !exec) + return ERROR_INVALID_PARAMETER; + length = RAIL_EXEC_ORDER_LENGTH + exec->exeOrFile.length + exec->workingDir.length + @@ -830,12 +928,14 @@ UINT rail_send_client_exec_order(railPlugin* rail, RAIL_EXEC_ORDER* exec) * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_send_client_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam) +static UINT rail_send_client_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam) { wStream* s; - int length; + size_t length = RAIL_SYSPARAM_ORDER_LENGTH; UINT error; - length = RAIL_SYSPARAM_ORDER_LENGTH; + + if (!rail || !sysparam) + return ERROR_INVALID_PARAMETER; switch (sysparam->param) { @@ -890,10 +990,13 @@ UINT rail_send_client_sysparam_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysp * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_send_client_sysparams_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam) +static UINT rail_send_client_sysparams_order(railPlugin* rail, RAIL_SYSPARAM_ORDER* sysparam) { UINT error = CHANNEL_RC_OK; + if (!rail || !sysparam) + return ERROR_INVALID_PARAMETER; + if (sysparam->params & SPI_MASK_SET_HIGH_CONTRAST) { sysparam->param = SPI_SET_HIGH_CONTRAST; @@ -984,15 +1087,22 @@ UINT rail_send_client_activate_order(railPlugin* rail, RAIL_ACTIVATE_ORDER* acti wStream* s; UINT error; + if (!rail || !activate) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_ACTIVATE_ORDER_LENGTH); + if (!s) { WLog_ERR(TAG, "rail_pdu_init failed!"); return CHANNEL_RC_NO_MEMORY; } - rail_write_client_activate_order(s, activate); - error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_ACTIVATE); + error = rail_write_client_activate_order(s, activate); + + if (error == ERROR_SUCCESS) + error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_ACTIVATE); + Stream_Free(s, TRUE); return error; } @@ -1006,6 +1116,10 @@ UINT rail_send_client_sysmenu_order(railPlugin* rail, RAIL_SYSMENU_ORDER* sysmen { wStream* s; UINT error; + + if (!rail || !sysmenu) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_SYSMENU_ORDER_LENGTH); if (!s) @@ -1014,8 +1128,11 @@ UINT rail_send_client_sysmenu_order(railPlugin* rail, RAIL_SYSMENU_ORDER* sysmen return CHANNEL_RC_NO_MEMORY; } - rail_write_client_sysmenu_order(s, sysmenu); - error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_SYSMENU); + error = rail_write_client_sysmenu_order(s, sysmenu); + + if (error == ERROR_SUCCESS) + error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_SYSMENU); + Stream_Free(s, TRUE); return error; } @@ -1029,6 +1146,10 @@ UINT rail_send_client_syscommand_order(railPlugin* rail, RAIL_SYSCOMMAND_ORDER* { wStream* s; UINT error; + + if (!rail || !syscommand) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_SYSCOMMAND_ORDER_LENGTH); if (!s) @@ -1037,8 +1158,11 @@ UINT rail_send_client_syscommand_order(railPlugin* rail, RAIL_SYSCOMMAND_ORDER* return CHANNEL_RC_NO_MEMORY; } - rail_write_client_syscommand_order(s, syscommand); - error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_SYSCOMMAND); + error = rail_write_client_syscommand_order(s, syscommand); + + if (error == ERROR_SUCCESS) + error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_SYSCOMMAND); + Stream_Free(s, TRUE); return error; } @@ -1052,6 +1176,10 @@ UINT rail_send_client_notify_event_order(railPlugin* rail, RAIL_NOTIFY_EVENT_ORD { wStream* s; UINT error; + + if (!rail || !notifyEvent) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_NOTIFY_EVENT_ORDER_LENGTH); if (!s) @@ -1060,8 +1188,11 @@ UINT rail_send_client_notify_event_order(railPlugin* rail, RAIL_NOTIFY_EVENT_ORD return CHANNEL_RC_NO_MEMORY; } - rail_write_client_notify_event_order(s, notifyEvent); - error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_NOTIFY_EVENT); + error = rail_write_client_notify_event_order(s, notifyEvent); + + if (ERROR_SUCCESS == error) + error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_NOTIFY_EVENT); + Stream_Free(s, TRUE); return error; } @@ -1075,6 +1206,10 @@ UINT rail_send_client_window_move_order(railPlugin* rail, RAIL_WINDOW_MOVE_ORDER { wStream* s; UINT error; + + if (!rail || !windowMove) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_WINDOW_MOVE_ORDER_LENGTH); if (!s) @@ -1083,8 +1218,11 @@ UINT rail_send_client_window_move_order(railPlugin* rail, RAIL_WINDOW_MOVE_ORDER return CHANNEL_RC_NO_MEMORY; } - rail_write_client_window_move_order(s, windowMove); - error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_WINDOWMOVE); + error = rail_write_client_window_move_order(s, windowMove); + + if (error == ERROR_SUCCESS) + error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_WINDOWMOVE); + Stream_Free(s, TRUE); return error; } @@ -1098,6 +1236,10 @@ UINT rail_send_client_get_appid_req_order(railPlugin* rail, RAIL_GET_APPID_REQ_O { wStream* s; UINT error; + + if (!rail || !getAppIdReq) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_GET_APPID_REQ_ORDER_LENGTH); if (!s) @@ -1106,8 +1248,11 @@ UINT rail_send_client_get_appid_req_order(railPlugin* rail, RAIL_GET_APPID_REQ_O return CHANNEL_RC_NO_MEMORY; } - rail_write_client_get_appid_req_order(s, getAppIdReq); - error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_GET_APPID_REQ); + error = rail_write_client_get_appid_req_order(s, getAppIdReq); + + if (error == ERROR_SUCCESS) + error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_GET_APPID_REQ); + Stream_Free(s, TRUE); return error; } @@ -1121,6 +1266,10 @@ UINT rail_send_client_langbar_info_order(railPlugin* rail, RAIL_LANGBAR_INFO_ORD { wStream* s; UINT error; + + if (!rail || !langBarInfo) + return ERROR_INVALID_PARAMETER; + s = rail_pdu_init(RAIL_LANGBAR_INFO_ORDER_LENGTH); if (!s) @@ -1129,8 +1278,11 @@ UINT rail_send_client_langbar_info_order(railPlugin* rail, RAIL_LANGBAR_INFO_ORD return CHANNEL_RC_NO_MEMORY; } - rail_write_langbar_info_order(s, langBarInfo); - error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_LANGBARINFO); + error = rail_write_langbar_info_order(s, langBarInfo); + + if (ERROR_SUCCESS == error) + error = rail_send_pdu(rail, s, RDP_RAIL_ORDER_LANGBARINFO); + Stream_Free(s, TRUE); return error; } diff --git a/channels/rail/rail_common.c b/channels/rail/rail_common.c index 3c05eb59d..ea344c316 100644 --- a/channels/rail/rail_common.c +++ b/channels/rail/rail_common.c @@ -55,9 +55,7 @@ void rail_string_to_unicode_string(char* string, RAIL_UNICODE_STRING* unicode_st { WCHAR* buffer = NULL; int length = 0; - free(unicode_string->string); - unicode_string->string = NULL; unicode_string->length = 0; @@ -65,7 +63,6 @@ void rail_string_to_unicode_string(char* string, RAIL_UNICODE_STRING* unicode_st return; length = ConvertToUnicode(CP_UTF8, 0, string, -1, &buffer, 0) * 2; - unicode_string->string = (BYTE*) buffer; unicode_string->length = (UINT16) length; } @@ -77,12 +74,14 @@ void rail_string_to_unicode_string(char* string, RAIL_UNICODE_STRING* unicode_st */ UINT rail_read_pdu_header(wStream* s, UINT16* orderType, UINT16* orderLength) { + if (!s || !orderType || !orderLength) + return ERROR_INVALID_PARAMETER; + if (Stream_GetRemainingLength(s) < 4) return ERROR_INVALID_DATA; Stream_Read_UINT16(s, *orderType); /* orderType (2 bytes) */ Stream_Read_UINT16(s, *orderLength); /* orderLength (2 bytes) */ - return CHANNEL_RC_OK; } @@ -96,8 +95,10 @@ wStream* rail_pdu_init(size_t length) { wStream* s; s = Stream_New(NULL, length + RAIL_PDU_HEADER_LENGTH); + if (!s) return NULL; + Stream_Seek(s, RAIL_PDU_HEADER_LENGTH); return s; } @@ -113,7 +114,6 @@ UINT rail_read_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake) return ERROR_INVALID_DATA; Stream_Read_UINT32(s, handshake->buildNumber); /* buildNumber (4 bytes) */ - return CHANNEL_RC_OK; } @@ -134,7 +134,6 @@ UINT rail_read_handshake_ex_order(wStream* s, RAIL_HANDSHAKE_EX_ORDER* handshake Stream_Read_UINT32(s, handshakeEx->buildNumber); /* buildNumber (4 bytes) */ Stream_Read_UINT32(s, handshakeEx->railHandshakeFlags); /* railHandshakeFlags (4 bytes) */ - return CHANNEL_RC_OK; } From ac1d6e81530a8d79898c308272f2ad1998491a08 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 20 Dec 2017 16:13:42 +0100 Subject: [PATCH 3/8] Fixed #3676, #4269: Screen update for RAIL with GFX --- client/X11/xf_gfx.c | 49 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index dd73d1ec8..6278efa6c 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -25,6 +25,7 @@ #include #include "xf_gfx.h" +#include "xf_rail.h" #define TAG CLIENT_TAG("x11") @@ -46,7 +47,6 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) XSetClipMask(xfc->display, xfc->gc, None); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); - region16_intersect_rect(&(surface->gdi.invalidRegion), &(surface->gdi.invalidRegion), &surfaceRect); @@ -73,22 +73,31 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) goto fail; } -#ifdef WITH_XRENDER - - if (xfc->context.settings->SmartSizing - || xfc->context.settings->MultiTouchGestures) + if (xfc->remote_app) { - XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image, - nXSrc, nYSrc, nXDst, nYDst, width, height); - xf_draw_screen(xfc, nXDst, nYDst, width, height); - } - else -#endif - { - XPutImage(xfc->display, xfc->drawable, xfc->gc, + XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image, nXSrc, nYSrc, nXDst, nYDst, width, height); + xf_lock_x11(xfc, FALSE); + xf_rail_paint(xfc, nXDst, nYDst, nXDst + width, nYDst + height); + xf_unlock_x11(xfc, FALSE); } + else +#ifdef WITH_XRENDER + if (xfc->context.settings->SmartSizing + || xfc->context.settings->MultiTouchGestures) + { + XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image, + nXSrc, nYSrc, nXDst, nYDst, width, height); + xf_draw_screen(xfc, nXDst, nYDst, width, height); + } + else +#endif + { + XPutImage(xfc->display, xfc->drawable, xfc->gc, + surface->image, nXSrc, nYSrc, + nXDst, nYDst, width, height); + } } rc = CHANNEL_RC_OK; @@ -215,12 +224,13 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, xfGfxSurface* surface; rdpGdi* gdi = (rdpGdi*)context->custom; xfContext* xfc = (xfContext*) gdi->context; + surface = (xfGfxSurface*) calloc(1, sizeof(xfGfxSurface)); - surface = (xfGfxSurface *) calloc(1, sizeof(xfGfxSurface)); if (!surface) return CHANNEL_RC_NO_MEMORY; surface->gdi.codecs = gdi->context->codecs; + if (!surface->gdi.codecs) { WLog_ERR(TAG, "%s: global GDI codecs aren't set", __FUNCTION__); @@ -250,13 +260,14 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, surface->gdi.scanline = surface->gdi.width * GetBytesPerPixel(surface->gdi.format); surface->gdi.scanline = x11_pad_scanline(surface->gdi.scanline, xfc->scanline_pad); size = surface->gdi.scanline * surface->gdi.height; - surface->gdi.data = (BYTE*)_aligned_malloc(size, 16); + if (!surface->gdi.data) { WLog_ERR(TAG, "%s: unable to allocate GDI data", __FUNCTION__); goto out_free; } + ZeroMemory(surface->gdi.data, size); if (AreColorFormatsEqualNoAlpha(gdi->dstFormat, surface->gdi.format)) @@ -272,15 +283,15 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, surface->stageScanline = width * bytes; surface->stageScanline = x11_pad_scanline(surface->stageScanline, xfc->scanline_pad); size = surface->stageScanline * surface->gdi.height; - surface->stage = (BYTE*) _aligned_malloc(size, 16); + if (!surface->stage) { WLog_ERR(TAG, "%s: unable to allocate stage buffer", __FUNCTION__); goto out_free_gdidata; } - ZeroMemory(surface->stage, size); + ZeroMemory(surface->stage, size); surface->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*) surface->stage, surface->gdi.width, surface->gdi.height, @@ -295,16 +306,16 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, surface->image->byte_order = LSBFirst; surface->image->bitmap_bit_order = LSBFirst; - surface->gdi.outputMapped = FALSE; region16_init(&surface->gdi.invalidRegion); + if (context->SetSurfaceData(context, surface->gdi.surfaceId, (void*) surface) != CHANNEL_RC_OK) { WLog_ERR(TAG, "%s: an error occurred during SetSurfaceData", __FUNCTION__); goto error_set_surface_data; } - return CHANNEL_RC_OK; + return CHANNEL_RC_OK; error_set_surface_data: XFree(surface->image); error_surface_image: From e23af1d2fc7de3c89846985443bc00d559786df1 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 20 Dec 2017 16:15:22 +0100 Subject: [PATCH 4/8] Fixed missing argument checks. --- client/X11/xf_rail.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index d4fec546b..45f20e84c 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -195,6 +195,10 @@ void xf_rail_invalidate_region(xfContext* xfc, REGION16* invalidRegion) xfAppWindow* appWindow; const RECTANGLE_16* extents; REGION16 windowInvalidRegion; + + if (!xfc || !xfc->rail || !xfc->railWindows) + return; + region16_init(&windowInvalidRegion); count = HashTable_GetKeys(xfc->railWindows, &pKeys); From 51e59e1f2e9706e33bb1a01f29bfcbc9c756ac92 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 20 Dec 2017 16:16:33 +0100 Subject: [PATCH 5/8] Check argument, xfc->window is NULL in RAILS mode --- client/X11/xf_disp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/X11/xf_disp.c b/client/X11/xf_disp.c index 835f56e4b..c007195ed 100644 --- a/client/X11/xf_disp.c +++ b/client/X11/xf_disp.c @@ -86,7 +86,8 @@ static BOOL xf_disp_set_window_resizable(xfDispContext *xfDisp) size_hints->win_gravity = NorthWestGravity; size_hints->min_width = size_hints->min_height = 320; size_hints->max_width = size_hints->max_height = 8192; - XSetWMNormalHints(xfDisp->xfc->display, xfDisp->xfc->window->handle, size_hints); + if (xfDisp->xfc->window) + XSetWMNormalHints(xfDisp->xfc->display, xfDisp->xfc->window->handle, size_hints); XFree(size_hints); return TRUE; } @@ -278,7 +279,7 @@ BOOL xf_disp_handle_configureNotify(xfContext *xfc, int width, int height) return TRUE; if (xfDisp->waitingResize || !xfDisp->activated || - (GetTickCount64() - xfDisp->lastSentDate < RESIZE_MIN_DELAY)) + (GetTickCount64() - xfDisp->lastSentDate < RESIZE_MIN_DELAY)) { WLog_DBG(TAG, "delaying resize to %dx%d", width, height); xfDisp->targetWidth = width; From 6950d95af0b2623f6739cd71c0d26212219fe79b Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 8 Feb 2018 16:53:09 +0100 Subject: [PATCH 6/8] Fix #4398: Ignore min/max info for non existing window. --- client/X11/xf_rail.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index 45f20e84c..f2149ee12 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -846,14 +846,15 @@ static UINT xf_rail_server_min_max_info(RailClientContext* context, appWindow = (xfAppWindow*) HashTable_GetItemValue(xfc->railWindows, (void*)(UINT_PTR) minMaxInfo->windowId); - if (!appWindow) - return ERROR_INTERNAL_ERROR; + if (appWindow) + { + xf_SetWindowMinMaxInfo(xfc, appWindow, + minMaxInfo->maxWidth, minMaxInfo->maxHeight, + minMaxInfo->maxPosX, minMaxInfo->maxPosY, + minMaxInfo->minTrackWidth, minMaxInfo->minTrackHeight, + minMaxInfo->maxTrackWidth, minMaxInfo->maxTrackHeight); + } - xf_SetWindowMinMaxInfo(xfc, appWindow, - minMaxInfo->maxWidth, minMaxInfo->maxHeight, - minMaxInfo->maxPosX, minMaxInfo->maxPosY, - minMaxInfo->minTrackWidth, minMaxInfo->minTrackHeight, - minMaxInfo->maxTrackWidth, minMaxInfo->maxTrackHeight); return CHANNEL_RC_OK; } From d181c794638fc8c7219b9cbcb11281c6e93661f3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 9 Feb 2018 09:35:26 +0100 Subject: [PATCH 7/8] Fixed rail window cleanup. --- client/X11/xf_rail.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index f2149ee12..fa717bb08 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -521,16 +521,12 @@ static BOOL xf_rail_window_common(rdpContext* context, static BOOL xf_rail_window_delete(rdpContext* context, WINDOW_ORDER_INFO* orderInfo) { - xfAppWindow* appWindow = NULL; xfContext* xfc = (xfContext*) context; - appWindow = (xfAppWindow*) HashTable_GetItemValue(xfc->railWindows, - (void*)(UINT_PTR) orderInfo->windowId); - if (!appWindow) - return TRUE; + if (!xfc) + return FALSE; HashTable_Remove(xfc->railWindows, (void*)(UINT_PTR) orderInfo->windowId); - xf_DestroyWindow(xfc, appWindow); return TRUE; } @@ -880,9 +876,23 @@ static UINT xf_rail_server_get_appid_response(RailClientContext* context, return CHANNEL_RC_OK; } +static void rail_window_free(void* value) +{ + xfAppWindow* appWindow = (xfAppWindow*) value; + + if (!appWindow) + return; + + xf_DestroyWindow(appWindow->xfc, appWindow); +} + int xf_rail_init(xfContext* xfc, RailClientContext* rail) { rdpContext* context = (rdpContext*) xfc; + + if (!xfc || !rail) + return 0; + xfc->rail = rail; xf_rail_register_update_callbacks(context->update); rail->custom = (void*) xfc; @@ -899,6 +909,7 @@ int xf_rail_init(xfContext* xfc, RailClientContext* rail) if (!xfc->railWindows) return 0; + xfc->railWindows->valueFree = rail_window_free; return 1; } From 47110a723d2bc1b050630b73b5c368b28dffcbcd Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 1 Mar 2018 12:39:29 +0100 Subject: [PATCH 8/8] Removed duplicate checks, more functions static. --- client/X11/xf_rail.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index fa717bb08..61be3e459 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -185,7 +185,7 @@ void xf_rail_end_local_move(xfContext* xfc, xfAppWindow* appWindow) appWindow->local_move.state = LMS_TERMINATING; } -void xf_rail_invalidate_region(xfContext* xfc, REGION16* invalidRegion) +static void xf_rail_invalidate_region(xfContext* xfc, REGION16* invalidRegion) { int index; int count; @@ -196,9 +196,6 @@ void xf_rail_invalidate_region(xfContext* xfc, REGION16* invalidRegion) const RECTANGLE_16* extents; REGION16 windowInvalidRegion; - if (!xfc || !xfc->rail || !xfc->railWindows) - return; - region16_init(&windowInvalidRegion); count = HashTable_GetKeys(xfc->railWindows, &pKeys); @@ -611,7 +608,7 @@ static BOOL xf_rail_non_monitored_desktop(rdpContext* context, return TRUE; } -void xf_rail_register_update_callbacks(rdpUpdate* update) +static void xf_rail_register_update_callbacks(rdpUpdate* update) { rdpWindowUpdate* window = update->window; window->WindowCreate = xf_rail_window_common;