From 273655a850f1ebfb5b4c0c3c4fe58c7b486d8395 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 18 Jun 2018 10:44:35 +0200 Subject: [PATCH] Follow up fix for #4631 Remember the callback state to avoid calling reerdp_channels_post_connect before the corresponding client callback has benn called. This might happen during redirection and reconnection. --- client/X11/xf_channels.h | 3 --- include/freerdp/freerdp.h | 4 +++- libfreerdp/core/client.c | 4 ++-- libfreerdp/core/connection.c | 8 ++------ libfreerdp/core/freerdp.c | 3 +++ 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/client/X11/xf_channels.h b/client/X11/xf_channels.h index ac91f84..8a8c3b1 100644 --- a/client/X11/xf_channels.h +++ b/client/X11/xf_channels.h @@ -32,9 +32,6 @@ #include #include -int xf_on_channel_connected(freerdp* instance, const char* name, void* pInterface); -int xf_on_channel_disconnected(freerdp* instance, const char* name, void* pInterface); - void xf_OnChannelConnectedEventHandler(void* context, ChannelConnectedEventArgs* e); void xf_OnChannelDisconnectedEventHandler(void* context, ChannelDisconnectedEventArgs* e); diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index 928dc1d..9b698e0 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -240,7 +240,9 @@ struct rdp_freerdp Callback for context deallocation Can be set before calling freerdp_context_free() to have it executed before deallocation. Must be set to NULL if not needed. */ - UINT64 paddingC[48 - 35]; /* 35 */ + UINT64 paddingC[47 - 35]; /* 35 */ + + ALIGN64 ConnectionCallbackState; /* 48 */ ALIGN64 pPreConnect PreConnect; /**< (offset 48) Callback for pre-connect operations. diff --git a/libfreerdp/core/client.c b/libfreerdp/core/client.c index c710ff0..cce7aa5 100644 --- a/libfreerdp/core/client.c +++ b/libfreerdp/core/client.c @@ -347,11 +347,11 @@ UINT freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance) UINT error = CHANNEL_RC_OK; UINT index; char* hostname; - int hostnameLength; + size_t hostnameLength; CHANNEL_CLIENT_DATA* pChannelClientData; channels->connected = TRUE; hostname = instance->settings->ServerHostname; - hostnameLength = (int) strlen(hostname); + hostnameLength = strlen(hostname); for (index = 0; index < channels->clientDataCount; index++) { diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 81df251..9db1fa4 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -357,7 +357,6 @@ BOOL rdp_client_redirect(rdpRdp* rdp) rdpSettings* settings; rdpContext* context; rdpChannels* channels; - BOOL connected; if (!rdp || !rdp->context || !rdp->context->channels) return FALSE; @@ -365,7 +364,6 @@ BOOL rdp_client_redirect(rdpRdp* rdp) settings = rdp->settings; context = rdp->context; channels = context->channels; - connected = channels->connected; if (!rdp_client_disconnect_and_clear(rdp)) return FALSE; @@ -426,7 +424,7 @@ BOOL rdp_client_redirect(rdpRdp* rdp) status = rdp_client_connect(rdp); - if (status && connected) + if (status && (context->instance->ConnectionCallbackState == 2)) status = (freerdp_channels_post_connect(context->channels, context->instance) == CHANNEL_RC_OK); return status; @@ -437,21 +435,19 @@ BOOL rdp_client_reconnect(rdpRdp* rdp) BOOL status; rdpContext* context; rdpChannels* channels; - BOOL connected; if (!rdp || !rdp->context || !rdp->context->channels) return FALSE; context = rdp->context; channels = context->channels; - connected = channels->connected; if (!rdp_client_disconnect_and_clear(rdp)) return FALSE; status = rdp_client_connect(rdp); - if (status && connected) + if (status && (context->instance->ConnectionCallbackState == 2)) status = (freerdp_channels_post_connect(channels, context->instance) == CHANNEL_RC_OK); return status; diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 676a6b8..c8c88ba 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -165,6 +165,7 @@ BOOL freerdp_connect(freerdp* instance) settings = instance->settings; instance->context->codecs = codecs_new(instance->context); IFCALLRET(instance->PreConnect, status, instance); + instance->ConnectionCallbackState++; if (status) status2 = freerdp_channels_pre_connect(instance->context->channels, @@ -212,6 +213,7 @@ BOOL freerdp_connect(freerdp* instance) } IFCALLRET(instance->PostConnect, status, instance); + instance->ConnectionCallbackState++; if (status) status2 = freerdp_channels_post_connect(instance->context->channels, instance); @@ -501,6 +503,7 @@ BOOL freerdp_disconnect(freerdp* instance) } IFCALL(instance->PostDisconnect, instance); + instance->ConnectionCallbackState++; if (instance->update->pcap_rfx) { -- 2.7.4