diff --git a/channels/rail/client/rail_main.c b/channels/rail/client/rail_main.c index 6671f48fd..e14cb524b 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 DWORD WINAPI rail_virtual_channel_client_thread(LPVOID 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 b38f9ca3c..7e489e3ab 100644 --- a/channels/rail/client/rail_orders.c +++ b/channels/rail/client/rail_orders.c @@ -32,7 +32,6 @@ #include "rail_orders.h" - /** * Function description * @@ -40,6 +39,9 @@ */ 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!"); @@ -58,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)) @@ -80,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); @@ -94,8 +103,11 @@ 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) { + 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) */ @@ -107,8 +119,11 @@ UINT rail_write_high_contrast(wStream* s, RAIL_HIGH_CONTRAST* highContrast) * * @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!"); @@ -128,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!"); @@ -163,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!"); @@ -188,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!"); @@ -212,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!"); @@ -231,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!"); @@ -243,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; } /** @@ -253,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) */ @@ -291,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) @@ -344,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; } /** @@ -396,11 +469,14 @@ 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; + 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); @@ -423,12 +499,15 @@ 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; + 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); @@ -451,10 +530,15 @@ 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; + + 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))) @@ -479,11 +563,15 @@ 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; + 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); @@ -506,12 +594,15 @@ 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; + 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); @@ -534,12 +625,16 @@ 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); 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); @@ -562,12 +657,15 @@ 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); 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); @@ -590,12 +688,15 @@ 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; + 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); @@ -624,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); @@ -688,7 +792,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; @@ -703,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) @@ -726,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) @@ -749,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) @@ -757,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; } @@ -773,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 + @@ -806,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) { @@ -866,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; @@ -960,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; } @@ -982,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) @@ -990,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; } @@ -1005,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) @@ -1013,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; } @@ -1028,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) @@ -1036,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; } @@ -1051,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) @@ -1059,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; } @@ -1074,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) @@ -1082,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; } @@ -1097,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) @@ -1105,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/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); 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; } diff --git a/client/X11/xf_disp.c b/client/X11/xf_disp.c index 251082768..49d9601a0 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; diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 909fa7d0b..b68a29714 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" #include @@ -74,22 +75,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; diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index d4fec546b..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; @@ -195,6 +195,7 @@ void xf_rail_invalidate_region(xfContext* xfc, REGION16* invalidRegion) xfAppWindow* appWindow; const RECTANGLE_16* extents; REGION16 windowInvalidRegion; + region16_init(&windowInvalidRegion); count = HashTable_GetKeys(xfc->railWindows, &pKeys); @@ -517,16 +518,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; } @@ -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; @@ -842,14 +839,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; } @@ -875,9 +873,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; @@ -894,6 +906,7 @@ int xf_rail_init(xfContext* xfc, RailClientContext* rail) if (!xfc->railWindows) return 0; + xfc->railWindows->valueFree = rail_window_free; return 1; }