[core] improve assertions and logging

This commit is contained in:
Armin Novak 2023-03-02 15:27:27 +01:00 committed by akallabeth
parent a726fa613a
commit 2450bf75e8
3 changed files with 55 additions and 10 deletions

View File

@ -730,7 +730,10 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp)
const rdpCertInfo* info = freerdp_certificate_get_info(settings->RdpServerCertificate);
if (!info)
{
WLog_ERR(TAG, "Failed to get rdpCertInfo from RdpServerCertificate");
return FALSE;
}
/*
* client random must be (bitlen / 8) + 8 - see [MS-RDPBCGR] 5.3.4.1
@ -1004,6 +1007,8 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
UINT32 i;
UINT16 channelId;
BOOL allJoined = TRUE;
WINPR_ASSERT(rdp);
rdpMcs* mcs = rdp->mcs;
if (!mcs_recv_channel_join_confirm(mcs, s, &channelId))
@ -1012,7 +1017,11 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
if (!mcs->userChannelJoined)
{
if (channelId != mcs->userId)
{
WLog_ERR(TAG, "expected user channel id %" PRIu16 ", but received %" PRIu16,
mcs->userId, channelId);
return FALSE;
}
mcs->userChannelJoined = TRUE;
if (!rdp_client_join_channel(rdp, MCS_GLOBAL_CHANNEL_ID))
@ -1021,8 +1030,11 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
else if (!mcs->globalChannelJoined)
{
if (channelId != MCS_GLOBAL_CHANNEL_ID)
{
WLog_ERR(TAG, "expected uglobalser channel id %" PRIu16 ", but received %" PRIu16,
MCS_GLOBAL_CHANNEL_ID, channelId);
return FALSE;
}
mcs->globalChannelJoined = TRUE;
if (mcs->messageChannelId != 0)
@ -1070,8 +1082,11 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s)
continue;
if (cur->ChannelId != channelId)
{
WLog_ERR(TAG, "expected channel id %" PRIu16 ", but received %" PRIu16,
MCS_GLOBAL_CHANNEL_ID, channelId);
return FALSE;
}
cur->joined = TRUE;
break;
}

View File

@ -482,7 +482,10 @@ static BOOL rdp_write_extended_info_packet(rdpRdp* rdp, wStream* s)
WCHAR* clientAddress = ConvertUtf8ToWCharAlloc(settings->ClientAddress, &cbClientAddress);
if (cbClientAddress > (UINT16_MAX / sizeof(WCHAR)))
{
WLog_ERR(TAG, "cbClientAddress > UINT16_MAX");
goto fail;
}
if (cbClientAddress > 0)
{
@ -501,7 +504,10 @@ static BOOL rdp_write_extended_info_packet(rdpRdp* rdp, wStream* s)
clientDir = ConvertUtf8ToWCharAlloc(settings->ClientDir, &cbClientDir);
if (cbClientDir > (UINT16_MAX / sizeof(WCHAR)))
{
WLog_ERR(TAG, "cbClientDir > UINT16_MAX");
goto fail;
}
if (cbClientDir > 0)
{
@ -518,7 +524,11 @@ static BOOL rdp_write_extended_info_packet(rdpRdp* rdp, wStream* s)
}
if (settings->ServerAutoReconnectCookie->cbLen > UINT16_MAX)
{
WLog_ERR(TAG, "ServerAutoreconnectCookie::cbLen > UINT16_MAX");
goto fail;
}
cbAutoReconnectCookie = (UINT16)settings->ServerAutoReconnectCookie->cbLen;
if (!Stream_EnsureRemainingCapacity(s, 4ull + cbClientAddress + 2ull + cbClientDir))
@ -749,9 +759,7 @@ static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s)
BOOL usedPasswordCookie = FALSE;
rdpSettings* settings;
if (!rdp || !s || !rdp->settings)
return FALSE;
WINPR_ASSERT(rdp);
settings = rdp->settings;
WINPR_ASSERT(settings);
@ -812,13 +820,19 @@ static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s)
domainW = freerdp_settings_get_string_as_utf16(settings, FreeRDP_Domain, &cbDomain);
if (cbDomain > UINT16_MAX / sizeof(WCHAR))
{
WLog_ERR(TAG, "cbDomain > UINT16_MAX");
goto fail;
}
cbDomain *= sizeof(WCHAR);
/* user name provided by the expert for connecting to the novice computer */
userNameW = freerdp_settings_get_string_as_utf16(settings, FreeRDP_Username, &cbUserName);
if (cbUserName > UINT16_MAX / sizeof(WCHAR))
{
WLog_ERR(TAG, "cbUserName > UINT16_MAX");
goto fail;
}
cbUserName *= sizeof(WCHAR);
const char* pin = "*";
@ -835,7 +849,10 @@ static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s)
} ptrconv;
if (settings->RedirectionPasswordLength > UINT16_MAX)
{
WLog_ERR(TAG, "RedirectionPasswordLength > UINT16_MAX");
goto fail;
}
usedPasswordCookie = TRUE;
ptrconv.bp = settings->RedirectionPassword;
@ -850,7 +867,10 @@ static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s)
{
passwordW = ConvertUtf8ToWCharAlloc(pin, &cbPassword);
if (cbPassword > UINT16_MAX / sizeof(WCHAR))
{
WLog_ERR(TAG, "cbPassword > UINT16_MAX");
goto fail;
}
cbPassword = (UINT16)cbPassword * sizeof(WCHAR);
}
@ -865,8 +885,16 @@ static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s)
if (altShell && strlen(altShell) > 0)
{
alternateShellW = ConvertUtf8ToWCharAlloc(altShell, &cbAlternateShell);
if (!alternateShellW || (cbAlternateShell > (UINT16_MAX / sizeof(WCHAR))))
if (!alternateShellW)
{
WLog_ERR(TAG, "alternateShellW == NULL");
goto fail;
}
if (cbAlternateShell > (UINT16_MAX / sizeof(WCHAR)))
{
WLog_ERR(TAG, "cbAlternateShell > UINT16_MAX");
goto fail;
}
cbAlternateShell = (UINT16)cbAlternateShell * sizeof(WCHAR);
}
@ -876,7 +904,10 @@ static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s)
workingDirW = freerdp_settings_get_string_as_utf16(settings, inputId, &cbWorkingDir);
if (cbWorkingDir > (UINT16_MAX / sizeof(WCHAR)))
{
WLog_ERR(TAG, "cbWorkingDir > UINT16_MAX");
goto fail;
}
cbWorkingDir = (UINT16)cbWorkingDir * sizeof(WCHAR);
if (!Stream_EnsureRemainingCapacity(s, 18ull + cbDomain + cbUserName + cbPassword +

View File

@ -1219,8 +1219,7 @@ BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channelId)
int status;
UINT16 length = 12;
if (!mcs)
return FALSE;
WINPR_ASSERT(mcs);
s = Stream_New(NULL, length);
@ -1252,8 +1251,8 @@ BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channelId)
UINT16 initiator;
UINT16 requested;
if (!mcs || !s || !channelId)
return FALSE;
WINPR_ASSERT(mcs);
WINPR_ASSERT(channelId);
if (!mcs_read_domain_mcspdu_header(s, DomainMCSPDU_ChannelJoinConfirm, &length, NULL))
return FALSE;