diff --git a/libfreerdp/core/gcc.c b/libfreerdp/core/gcc.c index 34ba5e53a..dc76a675c 100644 --- a/libfreerdp/core/gcc.c +++ b/libfreerdp/core/gcc.c @@ -42,11 +42,11 @@ static BOOL gcc_write_user_data_header(wStream* s, UINT16 type, UINT16 length); static BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs); static BOOL gcc_read_server_core_data(wStream* s, rdpMcs* mcs); -static BOOL gcc_write_server_core_data(wStream* s, const rdpMcs* mcs); +static BOOL gcc_write_server_core_data(wStream* s, rdpMcs* mcs); static BOOL gcc_read_client_security_data(wStream* s, rdpMcs* mcs, UINT16 blockLength); static BOOL gcc_write_client_security_data(wStream* s, const rdpMcs* mcs); static BOOL gcc_read_server_security_data(wStream* s, rdpMcs* mcs); -static BOOL gcc_write_server_security_data(wStream* s, const rdpMcs* mcs); +static BOOL gcc_write_server_security_data(wStream* s, rdpMcs* mcs); static BOOL gcc_read_client_network_data(wStream* s, rdpMcs* mcs, UINT16 blockLength); static BOOL gcc_write_client_network_data(wStream* s, const rdpMcs* mcs); static BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs); @@ -66,6 +66,26 @@ static BOOL gcc_write_client_multitransport_channel_data(wStream* s, const rdpMc static BOOL gcc_read_server_multitransport_channel_data(wStream* s, rdpMcs* mcs); static BOOL gcc_write_server_multitransport_channel_data(wStream* s, const rdpMcs* mcs); +static rdpSettings* mcs_get_settings(rdpMcs* mcs) +{ + WINPR_ASSERT(mcs); + + rdpContext* context = transport_get_context(mcs->transport); + WINPR_ASSERT(context); + + return context->settings; +} + +static const rdpSettings* mcs_get_const_settings(const rdpMcs* mcs) +{ + WINPR_ASSERT(mcs); + + const rdpContext* context = transport_get_context(mcs->transport); + WINPR_ASSERT(context); + + return context->settings; +} + static void append(char* buffer, size_t size, const char* what) { winpr_str_append(what, buffer, size, "|"); @@ -259,6 +279,8 @@ BOOL gcc_read_conference_create_request(wStream* s, rdpMcs* mcs) BYTE number; BYTE selection; + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); /* ConnectData */ if (!per_read_choice(s, &choice)) return FALSE; @@ -319,6 +341,8 @@ BOOL gcc_read_conference_create_request(wStream* s, rdpMcs* mcs) BOOL gcc_write_conference_create_request(wStream* s, wStream* userData) { + WINPR_ASSERT(s); + WINPR_ASSERT(userData); /* ConnectData */ if (!per_write_choice(s, 0)) /* From Key select object (0) of type OBJECT_IDENTIFIER */ return FALSE; @@ -360,7 +384,8 @@ BOOL gcc_read_conference_create_response(wStream* s, rdpMcs* mcs) BYTE result; BYTE choice; BYTE number; - + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); /* ConnectData */ if (!per_read_choice(s, &choice) || !per_read_object_identifier(s, t124_02_98_oid)) return FALSE; @@ -413,6 +438,8 @@ BOOL gcc_read_conference_create_response(wStream* s, rdpMcs* mcs) BOOL gcc_write_conference_create_response(wStream* s, wStream* userData) { + WINPR_ASSERT(s); + WINPR_ASSERT(userData); /* ConnectData */ if (!per_write_choice(s, 0)) return FALSE; @@ -451,6 +478,8 @@ BOOL gcc_write_conference_create_response(wStream* s, wStream* userData) BOOL gcc_read_client_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length) { + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); while (length > 0) { UINT16 type; @@ -540,16 +569,9 @@ BOOL gcc_read_client_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length) BOOL gcc_write_client_data_blocks(wStream* s, const rdpMcs* mcs) { - rdpContext* context; - rdpSettings* settings; + const rdpSettings* settings = mcs_get_const_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (!gcc_write_client_core_data(s, mcs) || !gcc_write_client_cluster_data(s, mcs) || @@ -650,6 +672,9 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length) UINT16 blockLength; BYTE* holdp; + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); + while (offset < length) { char buffer[64] = { 0 }; @@ -740,8 +765,10 @@ BOOL gcc_read_server_data_blocks(wStream* s, rdpMcs* mcs, UINT16 length) return TRUE; } -BOOL gcc_write_server_data_blocks(wStream* s, const rdpMcs* mcs) +BOOL gcc_write_server_data_blocks(wStream* s, rdpMcs* mcs) { + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); return gcc_write_server_core_data(s, mcs) && /* serverCoreData */ gcc_write_server_network_data(s, mcs) && /* serverNetworkData */ gcc_write_server_security_data(s, mcs) && /* serverSecurityData */ @@ -753,6 +780,7 @@ BOOL gcc_write_server_data_blocks(wStream* s, const rdpMcs* mcs) BOOL gcc_read_user_data_header(wStream* s, UINT16* type, UINT16* length) { + WINPR_ASSERT(s); if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) return FALSE; @@ -775,6 +803,8 @@ BOOL gcc_read_user_data_header(wStream* s, UINT16* type, UINT16* length) BOOL gcc_write_user_data_header(wStream* s, UINT16 type, UINT16 length) { + + WINPR_ASSERT(s); if (!Stream_EnsureRemainingCapacity(s, 4 + length)) return FALSE; Stream_Write_UINT16(s, type); /* type */ @@ -886,16 +916,9 @@ BOOL gcc_read_client_core_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) UINT16 supportedColorDepths = 0; UINT32 serverSelectedProtocol = 0; UINT16 earlyCapabilityFlags = 0; - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); /* Length of all required fields, until imeFileName */ @@ -1129,16 +1152,9 @@ BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs) UINT16 earlyCapabilityFlags; WCHAR* clientDigProductId = NULL; size_t clientDigProductIdLength; - rdpContext* context; - rdpSettings* settings; + const rdpSettings* settings = mcs_get_const_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (!gcc_write_user_data_header(s, CS_CORE, 234)) @@ -1223,16 +1239,9 @@ BOOL gcc_write_client_core_data(wStream* s, const rdpMcs* mcs) BOOL gcc_read_server_core_data(wStream* s, rdpMcs* mcs) { UINT32 serverVersion; - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) @@ -1259,19 +1268,15 @@ BOOL gcc_read_server_core_data(wStream* s, rdpMcs* mcs) settings->ConnectionType); } -BOOL gcc_write_server_core_data(wStream* s, const rdpMcs* mcs) +/* TODO: This function modifies rdpMcs + * TODO: Split this out of this function + */ +BOOL gcc_write_server_core_data(wStream* s, rdpMcs* mcs) { UINT32 earlyCapabilityFlags; - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (!gcc_write_user_data_header(s, SC_CORE, 16)) @@ -1295,16 +1300,9 @@ BOOL gcc_write_server_core_data(wStream* s, const rdpMcs* mcs) BOOL gcc_read_client_security_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) { - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (blockLength < 8) @@ -1336,16 +1334,9 @@ BOOL gcc_read_client_security_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) BOOL gcc_write_client_security_data(wStream* s, const rdpMcs* mcs) { - rdpContext* context; - rdpSettings* settings; + const rdpSettings* settings = mcs_get_const_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (!gcc_write_user_data_header(s, CS_SECURITY, 12)) @@ -1371,16 +1362,9 @@ BOOL gcc_read_server_security_data(wStream* s, rdpMcs* mcs) UINT32 length; BOOL validCryptoConfig = FALSE; UINT32 serverEncryptionMethod; - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) @@ -1552,23 +1536,19 @@ const BYTE tssk_privateExponent[] = { const BYTE tssk_exponent[] = { 0x5b, 0x7b, 0x88, 0xc0 }; -BOOL gcc_write_server_security_data(wStream* s, const rdpMcs* mcs) +/* TODO: This function does manipulate data in rdpMcs + * TODO: Split this out of this function + */ +BOOL gcc_write_server_security_data(wStream* s, rdpMcs* mcs) { BYTE* sigData; size_t expLen = 0, keyLen, sigDataLen; - BYTE encryptedSignature[TSSK_KEY_LENGTH]; - BYTE signature[sizeof(initial_signature)]; + BYTE encryptedSignature[TSSK_KEY_LENGTH] = { 0 }; + BYTE signature[sizeof(initial_signature)] = { 0 }; UINT32 headerLen, serverRandomLen, serverCertLen, wPublicKeyBlobLen; - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); /** @@ -1799,6 +1779,8 @@ BOOL gcc_read_client_network_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) { UINT32 i; + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); if (blockLength < 4) return FALSE; @@ -1848,7 +1830,8 @@ BOOL gcc_write_client_network_data(wStream* s, const rdpMcs* mcs) { UINT32 i; UINT16 length; - + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); if (mcs->channelCount > 0) { length = mcs->channelCount * 12 + 8; @@ -1875,7 +1858,8 @@ BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs) UINT16 MCSChannelId; UINT16 channelCount; UINT32 parsedChannelCount; - + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) return FALSE; @@ -1912,6 +1896,8 @@ BOOL gcc_read_server_network_data(wStream* s, rdpMcs* mcs) BOOL gcc_write_server_network_data(wStream* s, const rdpMcs* mcs) { UINT32 i; + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); const size_t payloadLen = 8 + mcs->channelCount * 2 + (mcs->channelCount % 2 == 1 ? 2 : 0); if (!gcc_write_user_data_header(s, SC_NET, payloadLen)) @@ -1942,16 +1928,9 @@ BOOL gcc_write_server_network_data(wStream* s, const rdpMcs* mcs) BOOL gcc_read_client_cluster_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) { UINT32 redirectedSessionId; - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (blockLength < 8) @@ -1988,16 +1967,9 @@ BOOL gcc_read_client_cluster_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) BOOL gcc_write_client_cluster_data(wStream* s, const rdpMcs* mcs) { UINT32 flags; - rdpContext* context; - rdpSettings* settings; + const rdpSettings* settings = mcs_get_const_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (!gcc_write_user_data_header(s, CS_CLUSTER, 12)) @@ -2026,16 +1998,9 @@ BOOL gcc_read_client_monitor_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) { UINT32 index; UINT32 monitorCount; - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (blockLength < 8) @@ -2098,16 +2063,9 @@ BOOL gcc_write_client_monitor_data(wStream* s, const rdpMcs* mcs) UINT32 i; UINT16 length; INT32 baseX = 0, baseY = 0; - rdpContext* context; - rdpSettings* settings; + const rdpSettings* settings = mcs_get_const_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); WLog_DBG(TAG, "[%s] MonitorCount=%" PRIu32, __FUNCTION__, settings->MonitorCount); @@ -2160,16 +2118,9 @@ BOOL gcc_read_client_monitor_extended_data(wStream* s, rdpMcs* mcs, UINT16 block UINT32 index; UINT32 monitorCount; UINT32 monitorAttributeSize; - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (blockLength < 12) @@ -2207,16 +2158,9 @@ BOOL gcc_write_client_monitor_extended_data(wStream* s, const rdpMcs* mcs) { UINT32 i; UINT16 length; - rdpContext* context; - rdpSettings* settings; + const rdpSettings* settings = mcs_get_const_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); if (settings->HasMonitorAttributes) @@ -2250,6 +2194,8 @@ BOOL gcc_write_client_monitor_extended_data(wStream* s, const rdpMcs* mcs) BOOL gcc_read_client_message_channel_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) { + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); if (blockLength < 4) return FALSE; @@ -2267,18 +2213,11 @@ BOOL gcc_read_client_message_channel_data(wStream* s, rdpMcs* mcs, UINT16 blockL BOOL gcc_write_client_message_channel_data(wStream* s, const rdpMcs* mcs) { - rdpContext* context; - rdpSettings* settings; + const rdpSettings* settings = mcs_get_const_settings(mcs); WINPR_ASSERT(s); WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); - if (freerdp_settings_get_bool(settings, FreeRDP_NetworkAutoDetect) || settings->SupportHeartbeatPdu || settings->SupportMultitransport) { @@ -2292,7 +2231,8 @@ BOOL gcc_write_client_message_channel_data(wStream* s, const rdpMcs* mcs) BOOL gcc_read_server_message_channel_data(wStream* s, rdpMcs* mcs) { UINT16 MCSChannelId; - + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) return FALSE; @@ -2304,6 +2244,8 @@ BOOL gcc_read_server_message_channel_data(wStream* s, rdpMcs* mcs) BOOL gcc_write_server_message_channel_data(wStream* s, const rdpMcs* mcs) { + WINPR_ASSERT(s); + WINPR_ASSERT(mcs); if (mcs->messageChannelId == 0) return TRUE; @@ -2323,18 +2265,10 @@ BOOL gcc_write_server_message_channel_data(wStream* s, const rdpMcs* mcs) BOOL gcc_read_client_multitransport_channel_data(wStream* s, rdpMcs* mcs, UINT16 blockLength) { - rdpContext* context; - rdpSettings* settings; + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); - if (blockLength < 4) return FALSE; @@ -2351,18 +2285,10 @@ BOOL gcc_read_client_multitransport_channel_data(wStream* s, rdpMcs* mcs, UINT16 BOOL gcc_write_client_multitransport_channel_data(wStream* s, const rdpMcs* mcs) { - rdpContext* context; - rdpSettings* settings; + const rdpSettings* settings = mcs_get_const_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); - if (!gcc_write_user_data_header(s, CS_MULTITRANSPORT, 8)) return FALSE; Stream_Write_UINT32(s, settings->MultitransportFlags); /* flags */ @@ -2371,19 +2297,9 @@ BOOL gcc_write_client_multitransport_channel_data(wStream* s, const rdpMcs* mcs) BOOL gcc_read_server_multitransport_channel_data(wStream* s, rdpMcs* mcs) { - - rdpContext* context; - rdpSettings* settings; - + rdpSettings* settings = mcs_get_settings(mcs); WINPR_ASSERT(s); - WINPR_ASSERT(mcs); - - context = transport_get_context(mcs->transport); - WINPR_ASSERT(context); - - settings = context->settings; WINPR_ASSERT(settings); - if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) return FALSE; @@ -2393,7 +2309,11 @@ BOOL gcc_read_server_multitransport_channel_data(wStream* s, rdpMcs* mcs) BOOL gcc_write_server_multitransport_channel_data(wStream* s, const rdpMcs* mcs) { + const rdpSettings* settings = mcs_get_const_settings(mcs); UINT32 flags = 0; + + WINPR_ASSERT(s); + WINPR_ASSERT(settings); if (!gcc_write_user_data_header(s, SC_MULTITRANSPORT, 8)) return FALSE; Stream_Write_UINT32(s, flags); /* flags (4 bytes) */ diff --git a/libfreerdp/core/gcc.h b/libfreerdp/core/gcc.h index 940ada7fd..02f8226a9 100644 --- a/libfreerdp/core/gcc.h +++ b/libfreerdp/core/gcc.h @@ -35,6 +35,6 @@ FREERDP_LOCAL BOOL gcc_write_conference_create_request(wStream* s, wStream* user FREERDP_LOCAL BOOL gcc_read_conference_create_response(wStream* s, rdpMcs* mcs); FREERDP_LOCAL BOOL gcc_write_conference_create_response(wStream* s, wStream* userData); FREERDP_LOCAL BOOL gcc_write_client_data_blocks(wStream* s, const rdpMcs* mcs); -FREERDP_LOCAL BOOL gcc_write_server_data_blocks(wStream* s, const rdpMcs* mcs); +FREERDP_LOCAL BOOL gcc_write_server_data_blocks(wStream* s, rdpMcs* mcs); #endif /* FREERDP_LIB_CORE_GCC_H */