From 917e392f1ec30dd8e01b7aba977fcf3f109f56d9 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 30 Nov 2022 14:33:31 +0100 Subject: [PATCH] [client] fix connection active checks * use freerdp_is_active_state for session active checks * fix state transitions --- libfreerdp/core/connection.c | 12 +++++------- libfreerdp/core/fastpath.c | 6 +++--- libfreerdp/core/rdp.c | 3 +-- libfreerdp/core/rdp.h | 8 -------- server/proxy/pf_input.c | 2 +- 5 files changed, 10 insertions(+), 21 deletions(-) diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 62eedbdc0..afbfce097 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -270,7 +270,7 @@ static BOOL rdp_client_wait_for_activation(rdpRdp* rdp) break; } - if (rdp_get_state(rdp) > CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE) + if (rdp_is_active_state(rdp)) return TRUE; } @@ -1213,6 +1213,7 @@ state_run_t rdp_client_connect_demand_active(rdpRdp* rdp, wStream* s) state_run_t rdp_client_connect_finalize(rdpRdp* rdp) { + WINPR_ASSERT(rdp); /** * [MS-RDPBCGR] 1.3.1.1 - 8. * The client-to-server PDUs sent during this phase have no dependencies on any of the @@ -1281,7 +1282,7 @@ BOOL rdp_client_transition_to_state(rdpRdp* rdp, CONNECTION_STATE state) return FALSE; break; - case CONNECTION_STATE_ACTIVE: + case CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE: { ActivatedEventArgs activatedEvent = { 0 }; rdpContext* context = rdp->context; @@ -1302,7 +1303,7 @@ BOOL rdp_client_transition_to_state(rdpRdp* rdp, CONNECTION_STATE state) rdpContext* context = rdp->context; EventArgsInit(&stateEvent, "libfreerdp"); stateEvent.state = rdp_get_state(rdp); - stateEvent.active = rdp_get_state(rdp) == CONNECTION_STATE_ACTIVE; + stateEvent.active = rdp_is_active_state(rdp); PubSub_OnConnectionStateChange(rdp->pubSub, context, &stateEvent); } @@ -1477,9 +1478,6 @@ BOOL rdp_server_accept_mcs_erect_domain_request(rdpRdp* rdp, wStream* s) BOOL rdp_server_accept_mcs_attach_user_request(rdpRdp* rdp, wStream* s) { - if (!rdp_server_transition_to_state(rdp, CONNECTION_STATE_MCS_ATTACH_USER)) - return FALSE; - if (!mcs_recv_attach_user_request(rdp->mcs, s)) return FALSE; @@ -1664,7 +1662,7 @@ BOOL rdp_server_transition_to_state(rdpRdp* rdp, CONNECTION_STATE state) if (cstate >= CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT) client = rdp->context->peer; - if (cstate < CONNECTION_STATE_ACTIVE) + if (!rdp_is_active_peer_state(cstate)) { if (client) client->activated = FALSE; diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index f179d683c..48d70a1ef 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -385,7 +385,7 @@ static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, wStream* case FASTPATH_UPDATETYPE_PTR_NULL: { - POINTER_SYSTEM_UPDATE pointer_system; + POINTER_SYSTEM_UPDATE pointer_system = { 0 }; pointer_system.type = SYSPTR_NULL; rc = IFCALLRESULT(defaultReturn, pointer->PointerSystem, context, &pointer_system); } @@ -393,7 +393,7 @@ static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, wStream* case FASTPATH_UPDATETYPE_PTR_DEFAULT: { - POINTER_SYSTEM_UPDATE pointer_system; + POINTER_SYSTEM_UPDATE pointer_system = { 0 }; pointer_system.type = SYSPTR_DEFAULT; rc = IFCALLRESULT(defaultReturn, pointer->PointerSystem, context, &pointer_system); } @@ -938,7 +938,7 @@ BOOL fastpath_send_multiple_input_pdu(rdpFastPath* fastpath, wStream* s, size_t WINPR_ASSERT(rdp); state = rdp_get_state(rdp); - if (state != CONNECTION_STATE_ACTIVE) + if (!rdp_is_active_state(rdp)) { WLog_WARN(TAG, "[%s] called before activation [%s]", __FUNCTION__, rdp_state_string(state)); goto fail; diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index 995a626e4..be3f06aee 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -1632,8 +1632,7 @@ static state_run_t rdp_handle_sc_flags(rdpRdp* rdp, wStream* s, UINT32 flag, if (!rdp_client_transition_to_state(rdp, nextState)) status = STATE_RUN_FAILED; else - status = (rdp_get_state(rdp) == CONNECTION_STATE_ACTIVE) ? STATE_RUN_ACTIVE - : STATE_RUN_SUCCESS; + status = STATE_RUN_SUCCESS; } else { diff --git a/libfreerdp/core/rdp.h b/libfreerdp/core/rdp.h index c0402ea9c..a39812ef6 100644 --- a/libfreerdp/core/rdp.h +++ b/libfreerdp/core/rdp.h @@ -105,14 +105,6 @@ typedef enum FINALIZE_DEACTIVATE_REACTIVATE = 0x200 } rdpFinalizePduType; -#define FINALIZE_SC_COMPLETE \ - (FINALIZE_SC_SYNCHRONIZE_PDU | FINALIZE_SC_CONTROL_COOPERATE_PDU | \ - FINALIZE_SC_CONTROL_GRANTED_PDU | FINALIZE_SC_FONT_MAP_PDU) -#define FINALIZE_CS_COMPLETE \ - (FINALIZE_CS_SYNCHRONIZE_PDU | FINALIZE_CS_CONTROL_COOPERATE_PDU | \ - FINALIZE_CS_CONTROL_REQUEST_PDU | FINALIZE_CS_PERSISTENT_KEY_LIST_PDU | \ - FINALIZE_CS_FONT_LIST_PDU) - /* Data PDU Types */ typedef enum { diff --git a/server/proxy/pf_input.c b/server/proxy/pf_input.c index 650b3dd5c..2ef7c20eb 100644 --- a/server/proxy/pf_input.c +++ b/server/proxy/pf_input.c @@ -33,7 +33,7 @@ static BOOL pf_server_check_and_sync_input_state(pClientContext* pc) { WINPR_ASSERT(pc); - if (freerdp_get_state(&pc->context) < CONNECTION_STATE_ACTIVE) + if (!freerdp_is_active_state(&pc->context)) return FALSE; if (pc->input_state_sync_pending) {