From e1ea441275e14317281025190ea17100b95e1e16 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sun, 6 May 2018 11:17:08 +0200 Subject: [PATCH] Fixed #4629: Only call freerdp_channels_post_connect when it was connected. In rdp_client_redirect or rdp_client_reconnect freerdp_channels_post_connect must be called if the channels were connected previously. This might not be the case, skip that call then. --- libfreerdp/core/connection.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 8d6ef93f9..81df25194 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -276,9 +276,9 @@ BOOL rdp_client_connect(rdpRdp* rdp) if (!freerdp_get_last_error(rdp->context)) { freerdp_set_last_error(rdp->context, FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED); - WLog_ERR(TAG, "Error: protocol security negotiation or connection failure"); } + return FALSE; } @@ -327,6 +327,7 @@ BOOL rdp_client_disconnect(rdpRdp* rdp) if (!nego_disconnect(rdp->nego)) return FALSE; + rdp_reset(rdp); rdp_client_transition_to_state(rdp, CONNECTION_STATE_INITIAL); @@ -344,7 +345,6 @@ BOOL rdp_client_disconnect_and_clear(rdpRdp* rdp) return FALSE; context = rdp->context; - context->LastError = FREERDP_ERROR_SUCCESS; clearChannelError(context); ResetEvent(context->abortEvent); @@ -356,12 +356,19 @@ BOOL rdp_client_redirect(rdpRdp* rdp) BOOL status; rdpSettings* settings; rdpContext* context; + rdpChannels* channels; + BOOL connected; - if (!rdp_client_disconnect_and_clear(rdp)) + if (!rdp || !rdp->context || !rdp->context->channels) return FALSE; settings = rdp->settings; context = rdp->context; + channels = context->channels; + connected = channels->connected; + + if (!rdp_client_disconnect_and_clear(rdp)) + return FALSE; if (rdp_redirection_apply_settings(rdp) != 0) return FALSE; @@ -373,7 +380,7 @@ BOOL rdp_client_redirect(rdpRdp* rdp) } else { - if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS) + if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS) { free(settings->ServerHostname); settings->ServerHostname = _strdup(settings->TargetNetAddress); @@ -419,7 +426,7 @@ BOOL rdp_client_redirect(rdpRdp* rdp) status = rdp_client_connect(rdp); - if (status) + if (status && connected) status = (freerdp_channels_post_connect(context->channels, context->instance) == CHANNEL_RC_OK); return status; @@ -428,15 +435,23 @@ BOOL rdp_client_redirect(rdpRdp* rdp) BOOL rdp_client_reconnect(rdpRdp* rdp) { BOOL status; - rdpContext* context = rdp->context; - rdpChannels* channels = context->channels; + 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) + if (status && connected) status = (freerdp_channels_post_connect(channels, context->instance) == CHANNEL_RC_OK); return status;