From c17c2f811b37cb5e3ebe806e0d10cdd9a1816ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20LeBlanc?= Date: Thu, 4 Jul 2013 14:42:40 -0400 Subject: [PATCH] FreeRDP: - replaced char* by const char* in function prototypes - MacFreeRDP: moved assignation of context function pointers - freerdp: added more pointer and return value validations to prevent crashes --- client/Mac/MRDPView.h | 5 +++++ client/Mac/MRDPView.m | 16 +--------------- client/Mac/mf_client.m | 7 ++++++- client/common/client.c | 2 +- client/common/file.c | 2 +- include/freerdp/client.h | 2 +- include/freerdp/client/file.h | 2 +- libfreerdp/core/connection.c | 19 +++++++++++++------ libfreerdp/core/gateway/tsg.c | 11 ++++++++++- winpr/libwinpr/synch/wait.c | 3 +++ 10 files changed, 42 insertions(+), 27 deletions(-) diff --git a/client/Mac/MRDPView.h b/client/Mac/MRDPView.h index cd4d06b03..653c2d391 100755 --- a/client/Mac/MRDPView.h +++ b/client/Mac/MRDPView.h @@ -109,3 +109,8 @@ #define PTR_FLAGS_BUTTON2 0x2000 #define PTR_FLAGS_BUTTON3 0x4000 #define WheelRotationMask 0x01FF + +BOOL mac_pre_connect(freerdp* instance); +BOOL mac_post_connect(freerdp* instance); +BOOL mac_authenticate(freerdp* instance, char** username, char** password, char** domain); +int mac_receive_channel_data(freerdp* instance, int chan_id, BYTE* data, int size, int flags, int total_size); diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index 6a67fbfcf..95dc36f0a 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -75,9 +75,6 @@ void mf_Pointer_Set(rdpContext* context, rdpPointer* pointer); void mf_Pointer_SetNull(rdpContext* context); void mf_Pointer_SetDefault(rdpContext* context); // int rdp_connect(void); -BOOL mac_pre_connect(freerdp* instance); -BOOL mac_post_connect(freerdp* instance); -BOOL mac_authenticate(freerdp* instance, char** username, char** password, char** domain); void mac_set_bounds(rdpContext* context, rdpBounds* bounds); void mac_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmap); void mac_begin_paint(rdpContext* context); @@ -141,17 +138,7 @@ struct rgba_data e.handle = (void*) self; PubSub_OnEmbedWindow(context->pubSub, context, &e); - context->instance->PreConnect = mac_pre_connect; - context->instance->PostConnect = mac_post_connect; - context->instance->ReceiveChannelData = mac_receive_channel_data; - context->instance->Authenticate = mac_authenticate; - - // TODO - // instance->Authenticate = mf_authenticate; - // instance->VerifyCertificate = mf_verify_certificate; - // instance->LogonErrorInfo = mf_logon_error_info; - - status = freerdp_connect(context->instance); + status = freerdp_connect(context->instance); if (!status) { @@ -797,7 +784,6 @@ struct rgba_data NSLog(@"Exception: %@", e); } @finally { - NSLog(@"finally"); } // set client area to specified dimensions diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index a88309184..900c488ed 100755 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -106,7 +106,12 @@ int mfreerdp_client_new(freerdp* instance, rdpContext* context) mfc = (mfContext*) instance->context; - context->channels = freerdp_channels_new(); + context->instance->PreConnect = mac_pre_connect; + context->instance->PostConnect = mac_post_connect; + context->instance->ReceiveChannelData = mac_receive_channel_data; + context->instance->Authenticate = mac_authenticate; + + context->channels = freerdp_channels_new(); settings = instance->settings; diff --git a/client/common/client.c b/client/common/client.c index acc47d064..b4979d32b 100644 --- a/client/common/client.c +++ b/client/common/client.c @@ -121,7 +121,7 @@ int freerdp_client_parse_command_line(rdpContext* context, int argc, char** argv return status; } -int freerdp_client_parse_connection_file(rdpContext* context, char* filename) +int freerdp_client_parse_connection_file(rdpContext* context, const char* filename) { rdpFile* file; diff --git a/client/common/file.c b/client/common/file.c index ea64826a7..c708f2b32 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -439,7 +439,7 @@ BOOL freerdp_client_parse_rdp_file_buffer(rdpFile* file, BYTE* buffer, size_t si return freerdp_client_parse_rdp_file_buffer_ascii(file, buffer, size); } -BOOL freerdp_client_parse_rdp_file(rdpFile* file, char* name) +BOOL freerdp_client_parse_rdp_file(rdpFile* file, const char* name) { BYTE* buffer; FILE* fp = NULL; diff --git a/include/freerdp/client.h b/include/freerdp/client.h index 67d7a5ebf..4edbd4f28 100644 --- a/include/freerdp/client.h +++ b/include/freerdp/client.h @@ -84,7 +84,7 @@ FREERDP_API freerdp* freerdp_client_get_instance(rdpContext* context); FREERDP_API HANDLE freerdp_client_get_thread(rdpContext* context); FREERDP_API int freerdp_client_parse_command_line(rdpContext* context, int argc, char** argv); -FREERDP_API int freerdp_client_parse_connection_file(rdpContext* context, char* filename); +FREERDP_API int freerdp_client_parse_connection_file(rdpContext* context, const char* filename); FREERDP_API int freerdp_client_parse_connection_file_buffer(rdpContext* context, BYTE* buffer, size_t size); #ifdef __cplusplus diff --git a/include/freerdp/client/file.h b/include/freerdp/client/file.h index e83aa5ced..cb9984d59 100644 --- a/include/freerdp/client/file.h +++ b/include/freerdp/client/file.h @@ -137,7 +137,7 @@ typedef struct rdp_file rdpFile; extern "C" { #endif -FREERDP_API BOOL freerdp_client_parse_rdp_file(rdpFile* file, char* name); +FREERDP_API BOOL freerdp_client_parse_rdp_file(rdpFile* file, const char* name); FREERDP_API BOOL freerdp_client_parse_rdp_file_buffer(rdpFile* file, BYTE* buffer, size_t size); FREERDP_API BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* settings); diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 34ae10881..247494e07 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -77,15 +77,19 @@ BOOL rdp_client_connect(rdpRdp* rdp) if (settings->GatewayEnabled) { - char* user; + char* user; char* domain; char* cookie; - int user_length; + int user_length = 0; int domain_length; int cookie_length; - user = settings->Username; - user_length = strlen(settings->Username); + + if (settings->Username) + { + user = settings->Username; + user_length = strlen(settings->Username); + } if (settings->Domain) domain = settings->Domain; @@ -100,8 +104,11 @@ BOOL rdp_client_connect(rdpRdp* rdp) CopyMemory(cookie, domain, domain_length); CharUpperBuffA(cookie, domain_length); cookie[domain_length] = '\\'; - CopyMemory(&cookie[domain_length + 1], user, user_length); - cookie[cookie_length] = '\0'; + + if (settings->Username) + CopyMemory(&cookie[domain_length + 1], user, user_length); + + cookie[cookie_length] = '\0'; nego_set_cookie(rdp->nego, cookie); free(cookie); diff --git a/libfreerdp/core/gateway/tsg.c b/libfreerdp/core/gateway/tsg.c index c6bb45dd1..cf013f2d8 100644 --- a/libfreerdp/core/gateway/tsg.c +++ b/libfreerdp/core/gateway/tsg.c @@ -1369,6 +1369,10 @@ BOOL tsg_disconnect(rdpTsg* tsg) * | | */ + + if (tsg == NULL) + return FALSE; + tsg->rpc->client->SynchronousReceive = TRUE; /* if we are already in state pending (i.e. if a server initiated disconnect was issued) @@ -1392,7 +1396,12 @@ BOOL tsg_disconnect(rdpTsg* tsg) int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length) { int CopyLength; - rdpRpc* rpc = tsg->rpc; + rdpRpc* rpc; + + if (tsg == NULL) + return -1; + + rpc = tsg->rpc; if (tsg->PendingPdu) { diff --git a/winpr/libwinpr/synch/wait.c b/winpr/libwinpr/synch/wait.c index 3006fe246..8060aa8ed 100644 --- a/winpr/libwinpr/synch/wait.c +++ b/winpr/libwinpr/synch/wait.c @@ -210,6 +210,9 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAl return WAIT_FAILED; } + if (fd == -1) + return WAIT_FAILED; + FD_SET(fd, &fds); if (fd > maxfd)