Added argument checks.

This commit is contained in:
Armin Novak 2017-12-20 15:00:21 +01:00
parent 674fae5ce6
commit 4dd0ccd703
3 changed files with 337 additions and 98 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}