WINPR_ASSERT activation.c

This commit is contained in:
Armin Novak 2021-09-06 11:39:26 +02:00 committed by akallabeth
parent 37ed889fd7
commit 81a2f9e434
1 changed files with 92 additions and 3 deletions

View File

@ -21,6 +21,8 @@
#include "config.h" #include "config.h"
#endif #endif
#include <winpr/assert.h>
#include "activation.h" #include "activation.h"
#include "display.h" #include "display.h"
@ -43,8 +45,11 @@ static BOOL rdp_recv_server_font_map_pdu(rdpRdp* rdp, wStream* s);
static BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, wStream* s); static BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, wStream* s);
static BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp); static BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp);
static BOOL rdp_write_synchronize_pdu(wStream* s, rdpSettings* settings) static BOOL rdp_write_synchronize_pdu(wStream* s, const rdpSettings* settings)
{ {
WINPR_ASSERT(s);
WINPR_ASSERT(settings);
if (Stream_GetRemainingCapacity(s) < 4) if (Stream_GetRemainingCapacity(s) < 4)
return FALSE; return FALSE;
Stream_Write_UINT16(s, SYNCMSGTYPE_SYNC); /* messageType (2 bytes) */ Stream_Write_UINT16(s, SYNCMSGTYPE_SYNC); /* messageType (2 bytes) */
@ -54,6 +59,10 @@ static BOOL rdp_write_synchronize_pdu(wStream* s, rdpSettings* settings)
BOOL rdp_recv_synchronize_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_recv_synchronize_pdu(rdpRdp* rdp, wStream* s)
{ {
WINPR_ASSERT(rdp);
WINPR_ASSERT(rdp->settings);
WINPR_ASSERT(s);
if (rdp->settings->ServerMode) if (rdp->settings->ServerMode)
return rdp_recv_server_synchronize_pdu(rdp, s); return rdp_recv_server_synchronize_pdu(rdp, s);
else else
@ -62,6 +71,9 @@ BOOL rdp_recv_synchronize_pdu(rdpRdp* rdp, wStream* s)
BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, wStream* s)
{ {
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
rdp->finalize_sc_pdus |= FINALIZE_SC_SYNCHRONIZE_PDU; rdp->finalize_sc_pdus |= FINALIZE_SC_SYNCHRONIZE_PDU;
return TRUE; return TRUE;
} }
@ -71,17 +83,25 @@ BOOL rdp_send_server_synchronize_pdu(rdpRdp* rdp)
wStream* s = rdp_data_pdu_init(rdp); wStream* s = rdp_data_pdu_init(rdp);
if (!s) if (!s)
return FALSE; return FALSE;
WINPR_ASSERT(rdp);
if (!rdp_write_synchronize_pdu(s, rdp->settings)) if (!rdp_write_synchronize_pdu(s, rdp->settings))
{ {
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return FALSE; return FALSE;
} }
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->userId); return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->userId);
} }
BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, wStream* s)
{ {
UINT16 messageType; UINT16 messageType;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
rdp->finalize_sc_pdus |= FINALIZE_SC_SYNCHRONIZE_PDU; rdp->finalize_sc_pdus |= FINALIZE_SC_SYNCHRONIZE_PDU;
if (Stream_GetRemainingLength(s) < 4) if (Stream_GetRemainingLength(s) < 4)
@ -102,16 +122,23 @@ BOOL rdp_send_client_synchronize_pdu(rdpRdp* rdp)
wStream* s = rdp_data_pdu_init(rdp); wStream* s = rdp_data_pdu_init(rdp);
if (!s) if (!s)
return FALSE; return FALSE;
WINPR_ASSERT(rdp);
if (!rdp_write_synchronize_pdu(s, rdp->settings)) if (!rdp_write_synchronize_pdu(s, rdp->settings))
{ {
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return FALSE; return FALSE;
} }
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->userId); return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->userId);
} }
static BOOL rdp_recv_control_pdu(wStream* s, UINT16* action) static BOOL rdp_recv_control_pdu(wStream* s, UINT16* action)
{ {
WINPR_ASSERT(s);
WINPR_ASSERT(action);
if (Stream_GetRemainingLength(s) < 8) if (Stream_GetRemainingLength(s) < 8)
return FALSE; return FALSE;
@ -123,6 +150,7 @@ static BOOL rdp_recv_control_pdu(wStream* s, UINT16* action)
static BOOL rdp_write_client_control_pdu(wStream* s, UINT16 action) static BOOL rdp_write_client_control_pdu(wStream* s, UINT16 action)
{ {
WINPR_ASSERT(s);
if (Stream_GetRemainingCapacity(s) < 8) if (Stream_GetRemainingCapacity(s) < 8)
return FALSE; return FALSE;
Stream_Write_UINT16(s, action); /* action (2 bytes) */ Stream_Write_UINT16(s, action); /* action (2 bytes) */
@ -135,6 +163,9 @@ BOOL rdp_recv_server_control_pdu(rdpRdp* rdp, wStream* s)
{ {
UINT16 action; UINT16 action;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
if (rdp_recv_control_pdu(s, &action) == FALSE) if (rdp_recv_control_pdu(s, &action) == FALSE)
return FALSE; return FALSE;
@ -166,6 +197,8 @@ BOOL rdp_send_server_control_cooperate_pdu(rdpRdp* rdp)
Stream_Write_UINT16(s, CTRLACTION_COOPERATE); /* action (2 bytes) */ Stream_Write_UINT16(s, CTRLACTION_COOPERATE); /* action (2 bytes) */
Stream_Write_UINT16(s, 0); /* grantId (2 bytes) */ Stream_Write_UINT16(s, 0); /* grantId (2 bytes) */
Stream_Write_UINT32(s, 0); /* controlId (4 bytes) */ Stream_Write_UINT32(s, 0); /* controlId (4 bytes) */
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId); return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId);
} }
@ -179,6 +212,8 @@ static BOOL rdp_send_server_control_granted_pdu(rdpRdp* rdp)
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return FALSE; return FALSE;
} }
WINPR_ASSERT(rdp->mcs);
Stream_Write_UINT16(s, CTRLACTION_GRANTED_CONTROL); /* action (2 bytes) */ Stream_Write_UINT16(s, CTRLACTION_GRANTED_CONTROL); /* action (2 bytes) */
Stream_Write_UINT16(s, rdp->mcs->userId); /* grantId (2 bytes) */ Stream_Write_UINT16(s, rdp->mcs->userId); /* grantId (2 bytes) */
Stream_Write_UINT32(s, 0x03EA); /* controlId (4 bytes) */ Stream_Write_UINT32(s, 0x03EA); /* controlId (4 bytes) */
@ -195,11 +230,15 @@ BOOL rdp_send_client_control_pdu(rdpRdp* rdp, UINT16 action)
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return FALSE; return FALSE;
} }
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId); return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->userId);
} }
static BOOL rdp_write_persistent_list_entry(wStream* s, UINT32 key1, UINT32 key2) static BOOL rdp_write_persistent_list_entry(wStream* s, UINT32 key1, UINT32 key2)
{ {
WINPR_ASSERT(s);
if (Stream_GetRemainingCapacity(s) < 8) if (Stream_GetRemainingCapacity(s) < 8)
return FALSE; return FALSE;
Stream_Write_UINT32(s, key1); /* key1 (4 bytes) */ Stream_Write_UINT32(s, key1); /* key1 (4 bytes) */
@ -209,6 +248,9 @@ static BOOL rdp_write_persistent_list_entry(wStream* s, UINT32 key1, UINT32 key2
static BOOL rdp_write_client_persistent_key_list_pdu(wStream* s, const rdpSettings* settings) static BOOL rdp_write_client_persistent_key_list_pdu(wStream* s, const rdpSettings* settings)
{ {
WINPR_ASSERT(s);
WINPR_ASSERT(settings);
if (Stream_GetRemainingCapacity(s) < 24) if (Stream_GetRemainingCapacity(s) < 24)
return FALSE; return FALSE;
Stream_Write_UINT16(s, 0); /* numEntriesCache0 (2 bytes) */ Stream_Write_UINT16(s, 0); /* numEntriesCache0 (2 bytes) */
@ -238,11 +280,14 @@ BOOL rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp)
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return FALSE; return FALSE;
} }
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST, rdp->mcs->userId); return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST, rdp->mcs->userId);
} }
BOOL rdp_recv_client_font_list_pdu(wStream* s) BOOL rdp_recv_client_font_list_pdu(wStream* s)
{ {
WINPR_ASSERT(s);
/* 2.2.1.18 Client Font List PDU */ /* 2.2.1.18 Client Font List PDU */
return Stream_SafeSeek(s, 8); return Stream_SafeSeek(s, 8);
} }
@ -252,6 +297,9 @@ BOOL rdp_recv_client_persistent_key_list_pdu(wStream* s)
BYTE flags; BYTE flags;
size_t count = 0; size_t count = 0;
UINT16 cache, x; UINT16 cache, x;
WINPR_ASSERT(s);
/* 2.2.1.17.1 Persistent Key List PDU Data (TS_BITMAPCACHE_PERSISTENT_LIST_PDU) */ /* 2.2.1.17.1 Persistent Key List PDU Data (TS_BITMAPCACHE_PERSISTENT_LIST_PDU) */
if (Stream_GetRemainingLength(s) < 21) if (Stream_GetRemainingLength(s) < 21)
return FALSE; return FALSE;
@ -277,6 +325,8 @@ BOOL rdp_recv_client_persistent_key_list_pdu(wStream* s)
static BOOL rdp_write_client_font_list_pdu(wStream* s, UINT16 flags) static BOOL rdp_write_client_font_list_pdu(wStream* s, UINT16 flags)
{ {
WINPR_ASSERT(s);
if (Stream_GetRemainingCapacity(s) < 8) if (Stream_GetRemainingCapacity(s) < 8)
return FALSE; return FALSE;
Stream_Write_UINT16(s, 0); /* numberFonts (2 bytes) */ Stream_Write_UINT16(s, 0); /* numberFonts (2 bytes) */
@ -296,11 +346,17 @@ BOOL rdp_send_client_font_list_pdu(rdpRdp* rdp, UINT16 flags)
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return FALSE; return FALSE;
} }
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_LIST, rdp->mcs->userId); return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_LIST, rdp->mcs->userId);
} }
BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, wStream* s)
{ {
WINPR_ASSERT(rdp);
WINPR_ASSERT(rdp->settings);
WINPR_ASSERT(s);
if (rdp->settings->ServerMode) if (rdp->settings->ServerMode)
return rdp_recv_server_font_map_pdu(rdp, s); return rdp_recv_server_font_map_pdu(rdp, s);
else else
@ -309,12 +365,18 @@ BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, wStream* s)
BOOL rdp_recv_server_font_map_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_recv_server_font_map_pdu(rdpRdp* rdp, wStream* s)
{ {
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
rdp->finalize_sc_pdus |= FINALIZE_SC_FONT_MAP_PDU; rdp->finalize_sc_pdus |= FINALIZE_SC_FONT_MAP_PDU;
return TRUE; return TRUE;
} }
BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, wStream* s)
{ {
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
rdp->finalize_sc_pdus |= FINALIZE_SC_FONT_MAP_PDU; rdp->finalize_sc_pdus |= FINALIZE_SC_FONT_MAP_PDU;
if (Stream_GetRemainingLength(s) >= 8) if (Stream_GetRemainingLength(s) >= 8)
@ -342,6 +404,8 @@ BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp)
Stream_Write_UINT16(s, 0); /* totalNumEntries (2 bytes) */ Stream_Write_UINT16(s, 0); /* totalNumEntries (2 bytes) */
Stream_Write_UINT16(s, FONTLIST_FIRST | FONTLIST_LAST); /* mapFlags (2 bytes) */ Stream_Write_UINT16(s, FONTLIST_FIRST | FONTLIST_LAST); /* mapFlags (2 bytes) */
Stream_Write_UINT16(s, 4); /* entrySize (2 bytes) */ Stream_Write_UINT16(s, 4); /* entrySize (2 bytes) */
WINPR_ASSERT(rdp->mcs);
return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_MAP, rdp->mcs->userId); return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_MAP, rdp->mcs->userId);
} }
@ -350,6 +414,9 @@ BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s)
UINT16 lengthSourceDescriptor; UINT16 lengthSourceDescriptor;
UINT32 timeout; UINT32 timeout;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
if (rdp_get_state(rdp) == CONNECTION_STATE_ACTIVE) if (rdp_get_state(rdp) == CONNECTION_STATE_ACTIVE)
rdp->deactivation_reactivation = TRUE; rdp->deactivation_reactivation = TRUE;
else else
@ -359,6 +426,8 @@ BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s)
* Windows XP can send short DEACTIVATE_ALL PDU that doesn't contain * Windows XP can send short DEACTIVATE_ALL PDU that doesn't contain
* the following fields. * the following fields.
*/ */
WINPR_ASSERT(rdp->settings);
if (Stream_GetRemainingLength(s) > 0) if (Stream_GetRemainingLength(s) > 0)
{ {
do do
@ -410,9 +479,13 @@ BOOL rdp_send_deactivate_all(rdpRdp* rdp)
if (Stream_GetRemainingCapacity(s) < 7) if (Stream_GetRemainingCapacity(s) < 7)
goto fail; goto fail;
WINPR_ASSERT(rdp->settings);
Stream_Write_UINT32(s, rdp->settings->ShareId); /* shareId (4 bytes) */ Stream_Write_UINT32(s, rdp->settings->ShareId); /* shareId (4 bytes) */
Stream_Write_UINT16(s, 1); /* lengthSourceDescriptor (2 bytes) */ Stream_Write_UINT16(s, 1); /* lengthSourceDescriptor (2 bytes) */
Stream_Write_UINT8(s, 0); /* sourceDescriptor (should be 0x00) */ Stream_Write_UINT8(s, 0); /* sourceDescriptor (should be 0x00) */
WINPR_ASSERT(rdp->mcs);
status = rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->userId); status = rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->userId);
fail: fail:
Stream_Release(s); Stream_Release(s);
@ -423,6 +496,9 @@ BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, wStream* s)
{ {
UINT16 action; UINT16 action;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
if (!rdp_recv_control_pdu(s, &action)) if (!rdp_recv_control_pdu(s, &action))
return FALSE; return FALSE;
@ -437,8 +513,18 @@ BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, wStream* s)
BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, wStream* s)
{ {
rdpSettings* settings = rdp->settings; rdpSettings* settings;
freerdp_peer* peer = rdp->context->peer; freerdp_peer* peer;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
settings = rdp->settings;
WINPR_ASSERT(settings);
WINPR_ASSERT(rdp->context);
peer = rdp->context->peer;
WINPR_ASSERT(peer);
if (!rdp_recv_client_font_list_pdu(s)) if (!rdp_recv_client_font_list_pdu(s))
return FALSE; return FALSE;
@ -479,6 +565,9 @@ BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, wStream* s)
BOOL rdp_server_accept_client_persistent_key_list_pdu(rdpRdp* rdp, wStream* s) BOOL rdp_server_accept_client_persistent_key_list_pdu(rdpRdp* rdp, wStream* s)
{ {
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
if (!rdp_recv_client_persistent_key_list_pdu(s)) if (!rdp_recv_client_persistent_key_list_pdu(s))
return FALSE; return FALSE;