From fdcc36dd8d9cb7b3569a3814f70dad5e3671aa35 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 28 Apr 2023 08:23:52 +0200 Subject: [PATCH] [core,connection] relax state machine contrary to '[MS-RDPBCGR] 1.3.9 Connect-Time and Continuous Network Characteristics Detection' we have seen autodetection reqeusts mixed in between licensing messages. This relaxes the state machine and allows handling. --- libfreerdp/core/connection.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 2eb2ef11a..ca11ef174 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -1109,10 +1109,6 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s) BOOL rdp_client_connect_auto_detect(rdpRdp* rdp, wStream* s) { - size_t pos; - UINT16 length; - UINT16 channelId; - WINPR_ASSERT(rdp); WINPR_ASSERT(rdp->mcs); @@ -1121,7 +1117,9 @@ BOOL rdp_client_connect_auto_detect(rdpRdp* rdp, wStream* s) if (messageChannelId != 0) { /* Process any MCS message channel PDUs. */ - pos = Stream_GetPosition(s); + const size_t pos = Stream_GetPosition(s); + UINT16 length = 0; + UINT16 channelId = 0; if (rdp_read_header(rdp, s, &length, &channelId)) { @@ -1172,6 +1170,15 @@ state_run_t rdp_client_connect_license(rdpRdp* rdp, wStream* s) return STATE_RUN_FAILED; } + /* there might be autodetect messages mixed in between licensing messages. + * that has been observed with 2k12 R2 and 2k19 + */ + const UINT16 messageChannelId = rdp->mcs->messageChannelId; + if (channelId == messageChannelId) + { + return rdp_recv_message_channel_pdu(rdp, s, securityFlags); + } + if ((securityFlags & SEC_LICENSE_PKT) == 0) { char buffer[512] = { 0 };