From 6ee60ea15af228ba4cf8543764058337544f3207 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 29 Nov 2021 14:29:07 +0100 Subject: [PATCH] Fixed various warnings --- libfreerdp/codec/rfx.c | 192 ++++++++++++++-------------- libfreerdp/core/info.c | 9 +- libfreerdp/core/mcs.c | 2 - winpr/libwinpr/utils/test/TestIni.c | 2 +- 4 files changed, 107 insertions(+), 98 deletions(-) diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 0481236ee..75ebe4be9 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -899,114 +899,118 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa /* tiles */ close_cnt = 0; - rc = TRUE; + rc = FALSE; - for (i = 0; i < message->numTiles; i++) + if (Stream_GetRemainingLength(s) >= tilesDataSize) { - wStream subBuffer; - wStream* sub; + rc = TRUE; + for (i = 0; i < message->numTiles; i++) + { + wStream subBuffer; + wStream* sub; - if (!(tile = (RFX_TILE*)ObjectPool_Take(context->priv->TilePool))) - { - WLog_ERR(TAG, "RfxMessageTileSet failed to get tile from object pool"); - rc = FALSE; - break; - } - - message->tiles[i] = tile; - - /* RFX_TILE */ - if (Stream_GetRemainingLength(s) < 6) - { - WLog_ERR(TAG, "RfxMessageTileSet packet too small to read tile %d/%" PRIu16 "", i, - message->numTiles); - rc = FALSE; - break; - } - - sub = Stream_StaticInit(&subBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s)); - Stream_Read_UINT16(sub, - blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */ - Stream_Read_UINT32(sub, blockLen); /* blockLen (4 bytes) */ - - if (!Stream_SafeSeek(s, blockLen)) - { - rc = FALSE; - break; - } - if ((blockLen < 6 + 13) || (Stream_GetRemainingLength(sub) < blockLen - 6)) - { - WLog_ERR(TAG, - "RfxMessageTileSet not enough bytes to read tile %d/%" PRIu16 - " with blocklen=%" PRIu32 "", - i, message->numTiles, blockLen); - rc = FALSE; - break; - } - - if (blockType != CBT_TILE) - { - WLog_ERR(TAG, "unknown block type 0x%" PRIX32 ", expected CBT_TILE (0xCAC3).", - blockType); - rc = FALSE; - break; - } - - Stream_Read_UINT8(sub, tile->quantIdxY); /* quantIdxY (1 byte) */ - Stream_Read_UINT8(sub, tile->quantIdxCb); /* quantIdxCb (1 byte) */ - Stream_Read_UINT8(sub, tile->quantIdxCr); /* quantIdxCr (1 byte) */ - Stream_Read_UINT16(sub, tile->xIdx); /* xIdx (2 bytes) */ - Stream_Read_UINT16(sub, tile->yIdx); /* yIdx (2 bytes) */ - Stream_Read_UINT16(sub, tile->YLen); /* YLen (2 bytes) */ - Stream_Read_UINT16(sub, tile->CbLen); /* CbLen (2 bytes) */ - Stream_Read_UINT16(sub, tile->CrLen); /* CrLen (2 bytes) */ - Stream_GetPointer(sub, tile->YData); - if (!Stream_SafeSeek(sub, tile->YLen)) - { - rc = FALSE; - break; - } - Stream_GetPointer(sub, tile->CbData); - if (!Stream_SafeSeek(sub, tile->CbLen)) - { - rc = FALSE; - break; - } - Stream_GetPointer(sub, tile->CrData); - if (!Stream_SafeSeek(sub, tile->CrLen)) - { - rc = FALSE; - break; - } - tile->x = tile->xIdx * 64; - tile->y = tile->yIdx * 64; - - if (context->priv->UseThreads) - { - if (!params) + if (!(tile = (RFX_TILE*)ObjectPool_Take(context->priv->TilePool))) { + WLog_ERR(TAG, "RfxMessageTileSet failed to get tile from object pool"); rc = FALSE; break; } - params[i].context = context; - params[i].tile = message->tiles[i]; + message->tiles[i] = tile; - if (!(work_objects[i] = - CreateThreadpoolWork(rfx_process_message_tile_work_callback, - (void*)¶ms[i], &context->priv->ThreadPoolEnv))) + /* RFX_TILE */ + if (Stream_GetRemainingLength(s) < 6) { - WLog_ERR(TAG, "CreateThreadpoolWork failed."); + WLog_ERR(TAG, "RfxMessageTileSet packet too small to read tile %d/%" PRIu16 "", i, + message->numTiles); rc = FALSE; break; } - SubmitThreadpoolWork(work_objects[i]); - close_cnt = i + 1; - } - else - { - rfx_decode_rgb(context, tile, tile->data, 64 * 4); + sub = Stream_StaticInit(&subBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s)); + Stream_Read_UINT16( + sub, blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */ + Stream_Read_UINT32(sub, blockLen); /* blockLen (4 bytes) */ + + if (!Stream_SafeSeek(s, blockLen)) + { + rc = FALSE; + break; + } + if ((blockLen < 6 + 13) || (Stream_GetRemainingLength(sub) < blockLen - 6)) + { + WLog_ERR(TAG, + "RfxMessageTileSet not enough bytes to read tile %d/%" PRIu16 + " with blocklen=%" PRIu32 "", + i, message->numTiles, blockLen); + rc = FALSE; + break; + } + + if (blockType != CBT_TILE) + { + WLog_ERR(TAG, "unknown block type 0x%" PRIX32 ", expected CBT_TILE (0xCAC3).", + blockType); + rc = FALSE; + break; + } + + Stream_Read_UINT8(sub, tile->quantIdxY); /* quantIdxY (1 byte) */ + Stream_Read_UINT8(sub, tile->quantIdxCb); /* quantIdxCb (1 byte) */ + Stream_Read_UINT8(sub, tile->quantIdxCr); /* quantIdxCr (1 byte) */ + Stream_Read_UINT16(sub, tile->xIdx); /* xIdx (2 bytes) */ + Stream_Read_UINT16(sub, tile->yIdx); /* yIdx (2 bytes) */ + Stream_Read_UINT16(sub, tile->YLen); /* YLen (2 bytes) */ + Stream_Read_UINT16(sub, tile->CbLen); /* CbLen (2 bytes) */ + Stream_Read_UINT16(sub, tile->CrLen); /* CrLen (2 bytes) */ + Stream_GetPointer(sub, tile->YData); + if (!Stream_SafeSeek(sub, tile->YLen)) + { + rc = FALSE; + break; + } + Stream_GetPointer(sub, tile->CbData); + if (!Stream_SafeSeek(sub, tile->CbLen)) + { + rc = FALSE; + break; + } + Stream_GetPointer(sub, tile->CrData); + if (!Stream_SafeSeek(sub, tile->CrLen)) + { + rc = FALSE; + break; + } + tile->x = tile->xIdx * 64; + tile->y = tile->yIdx * 64; + + if (context->priv->UseThreads) + { + if (!params) + { + rc = FALSE; + break; + } + + params[i].context = context; + params[i].tile = message->tiles[i]; + + if (!(work_objects[i] = + CreateThreadpoolWork(rfx_process_message_tile_work_callback, + (void*)¶ms[i], &context->priv->ThreadPoolEnv))) + { + WLog_ERR(TAG, "CreateThreadpoolWork failed."); + rc = FALSE; + break; + } + + SubmitThreadpoolWork(work_objects[i]); + close_cnt = i + 1; + } + else + { + rfx_decode_rgb(context, tile, tile->data, 64 * 4); + } } } diff --git a/libfreerdp/core/info.c b/libfreerdp/core/info.c index dd105461b..d83296046 100644 --- a/libfreerdp/core/info.c +++ b/libfreerdp/core/info.c @@ -1005,15 +1005,22 @@ static BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, wStream* s, logon_info* info) UINT32 Size; UINT32 cbDomain; UINT32 cbUserName; + const size_t logonInfoV2Size = 576; WINPR_UNUSED(rdp); ZeroMemory(info, sizeof(*info)); - if (Stream_GetRemainingLength(s) < 576) + if (Stream_GetRemainingLength(s) < logonInfoV2Size) return FALSE; Stream_Read_UINT16(s, Version); /* Version (2 bytes) */ + if (Version != SAVE_SESSION_PDU_VERSION_ONE) + return FALSE; + Stream_Read_UINT32(s, Size); /* Size (4 bytes) */ + if (Size != 18) + return FALSE; + Stream_Read_UINT32(s, info->sessionId); /* SessionId (4 bytes) */ Stream_Read_UINT32(s, cbDomain); /* cbDomain (4 bytes) */ Stream_Read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */ diff --git a/libfreerdp/core/mcs.c b/libfreerdp/core/mcs.c index 874736fe7..2de140442 100644 --- a/libfreerdp/core/mcs.c +++ b/libfreerdp/core/mcs.c @@ -1111,7 +1111,6 @@ BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channelId) BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channelId) { - BOOL status; UINT16 length; BYTE result; UINT16 initiator; @@ -1121,7 +1120,6 @@ BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channelId) if (!mcs || !s || !channelId) return FALSE; - status = TRUE; MCSPDU = DomainMCSPDU_ChannelJoinConfirm; if (!mcs_read_domain_mcspdu_header(s, &MCSPDU, &length)) return FALSE; diff --git a/winpr/libwinpr/utils/test/TestIni.c b/winpr/libwinpr/utils/test/TestIni.c index 93789c8b1..8d68647ee 100644 --- a/winpr/libwinpr/utils/test/TestIni.c +++ b/winpr/libwinpr/utils/test/TestIni.c @@ -157,5 +157,5 @@ fail: free(keyNames); free(sectionNames); IniFile_Free(ini); - return 0; + return rc; }