From: asapelkin Date: Wed, 16 Oct 2019 16:49:24 +0000 (+0300) Subject: Fix some static analizer warnings X-Git-Tag: 2.0.0~301 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=82eadad4a4d26e877d91ec3fa54feb30293e1de7;p=platform%2Fupstream%2Ffreerdp.git Fix some static analizer warnings --- diff --git a/channels/rdpei/client/rdpei_main.c b/channels/rdpei/client/rdpei_main.c index f668159..9aca258 100644 --- a/channels/rdpei/client/rdpei_main.c +++ b/channels/rdpei/client/rdpei_main.c @@ -173,9 +173,9 @@ static DWORD WINAPI rdpei_schedule_thread(LPVOID arg) { DWORD status; RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) arg; - RdpeiClientContext* context = (RdpeiClientContext*) rdpei->iface.pInterface; - HANDLE hdl[] = {rdpei->event, rdpei->stopEvent}; UINT error = CHANNEL_RC_OK; + RdpeiClientContext* context; + HANDLE hdl[2]; if (!rdpei) { @@ -183,6 +183,10 @@ static DWORD WINAPI rdpei_schedule_thread(LPVOID arg) goto out; } + context = (RdpeiClientContext*) rdpei->iface.pInterface; + hdl[0] = rdpei->event; + hdl[1] = rdpei->stopEvent; + if (!context) { error = ERROR_INVALID_PARAMETER; diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 0d22247..5fbf7e7 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -122,7 +122,7 @@ static UINT xf_UpdateSurfaces(RdpgfxClientContext* context) UINT status = CHANNEL_RC_OK; UINT16* pSurfaceIds = NULL; rdpGdi* gdi = (rdpGdi*)context->custom; - xfContext* xfc = (xfContext*) gdi->context; + xfContext* xfc; if (!gdi) return status; @@ -133,6 +133,7 @@ static UINT xf_UpdateSurfaces(RdpgfxClientContext* context) if (gdi->suppressOutput) return CHANNEL_RC_OK; + xfc = (xfContext*) gdi->context; EnterCriticalSection(&context->mux); context->GetSurfaceIds(context, &pSurfaceIds, &count); diff --git a/libfreerdp/cache/glyph.c b/libfreerdp/cache/glyph.c index d3b7105..9124aea 100644 --- a/libfreerdp/cache/glyph.c +++ b/libfreerdp/cache/glyph.c @@ -453,9 +453,6 @@ static BOOL update_gdi_fast_glyph(rdpContext* context, rdpGlyph* glyph; const GLYPH_DATA_V2* glyphData = &fastGlyph->glyphData; - if (!glyphData) - return FALSE; - glyph = Glyph_Alloc(context, glyphData->x, glyphData->y, glyphData->cx, glyphData->cy, glyphData->cb, glyphData->aj); @@ -727,30 +724,27 @@ void glyph_cache_free(rdpGlyphCache* glyphCache) int i; GLYPH_CACHE* cache = glyphCache->glyphCache; - if (cache) + for (i = 0; i < 10; i++) { - for (i = 0; i < 10; i++) - { - UINT32 j; - rdpGlyph** entries = cache[i].entries; + UINT32 j; + rdpGlyph** entries = cache[i].entries; - if (!entries) - continue; + if (!entries) + continue; - for (j = 0; j < cache[i].number; j++) - { - rdpGlyph* glyph = entries[j]; + for (j = 0; j < cache[i].number; j++) + { + rdpGlyph* glyph = entries[j]; - if (glyph) - { - glyph->Free(glyphCache->context, glyph); - entries[j] = NULL; - } + if (glyph) + { + glyph->Free(glyphCache->context, glyph); + entries[j] = NULL; } - - free(entries); - cache[i].entries = NULL; } + + free(entries); + cache[i].entries = NULL; } if (glyphCache->fragCache.entries) diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index ef5ff7b..e02fac6 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -1000,13 +1000,15 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length, REGION16 updateRegion; UINT32 blockLen; UINT32 blockType; - RFX_MESSAGE* message = &context->currentMessage; wStream inStream, *s = &inStream; BOOL ok = TRUE; + RFX_MESSAGE* message; if (!context || !data || !length) return FALSE; + message = &context->currentMessage; + Stream_StaticInit(s, (BYTE*)data, length); message->freeRects = TRUE; diff --git a/libfreerdp/codec/xcrush.c b/libfreerdp/codec/xcrush.c index 5df7816..e98ff15 100644 --- a/libfreerdp/codec/xcrush.c +++ b/libfreerdp/codec/xcrush.c @@ -874,8 +874,7 @@ static int xcrush_compress_l1(XCRUSH_CONTEXT* xcrush, BYTE* pSrcData, UINT32 Src if (status < 0) return status; - if (status > 0) - Flags |= L1_COMPRESSED; + Flags |= L1_COMPRESSED; } } } diff --git a/libfreerdp/common/assistance.c b/libfreerdp/common/assistance.c index 6ac7411..d77382b 100644 --- a/libfreerdp/common/assistance.c +++ b/libfreerdp/common/assistance.c @@ -563,9 +563,6 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas if (!pbIn || !pbOut) goto fail; - if ((EncryptedSize == 0) || (cbPassStubW > UINT32_MAX)) - goto fail; - *((UINT32*) pbIn) = (UINT32)cbPassStubW; CopyMemory(&pbIn[4], PassStubW, cbPassStubW); rc4Ctx = winpr_Cipher_New(WINPR_CIPHER_ARC4_128, WINPR_ENCRYPT, diff --git a/libfreerdp/core/client.c b/libfreerdp/core/client.c index c1ec37c..5c8e08a 100644 --- a/libfreerdp/core/client.c +++ b/libfreerdp/core/client.c @@ -678,7 +678,10 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelInitEx(LPVOID lpUserParam, LPVOID cl if (!pInitHandle) return CHANNEL_RC_BAD_INIT_HANDLE; - if (!pChannel || (channelCount <= 0) || !pChannelInitEventProcEx) + if (!pChannel) + return CHANNEL_RC_BAD_CHANNEL; + + if ((channelCount <= 0) || !pChannelInitEventProcEx) return CHANNEL_RC_INITIALIZATION_ERROR; pChannelInitData = (CHANNEL_INIT_DATA*) pInitHandle; @@ -691,9 +694,6 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelInitEx(LPVOID lpUserParam, LPVOID cl if ((channels->openDataCount + channelCount) > CHANNEL_MAX_COUNT) return CHANNEL_RC_TOO_MANY_CHANNELS; - if (!pChannel) - return CHANNEL_RC_BAD_CHANNEL; - if (channels->connected) return CHANNEL_RC_ALREADY_CONNECTED; @@ -763,7 +763,10 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelInit(LPVOID* ppInitHandle, if (!ppInitHandle || !channels) return CHANNEL_RC_BAD_INIT_HANDLE; - if (!pChannel || (channelCount <= 0) || !pChannelInitEventProc) + if (!pChannel) + return CHANNEL_RC_BAD_CHANNEL; + + if ((channelCount <= 0) || !pChannelInitEventProc) return CHANNEL_RC_INITIALIZATION_ERROR; pInterface = g_pInterface; @@ -779,9 +782,6 @@ static UINT VCAPITYPE FreeRDP_VirtualChannelInit(LPVOID* ppInitHandle, if (channels->openDataCount + channelCount > CHANNEL_MAX_COUNT) return CHANNEL_RC_TOO_MANY_CHANNELS; - if (!pChannel) - return CHANNEL_RC_BAD_CHANNEL; - if (channels->connected) return CHANNEL_RC_ALREADY_CONNECTED; diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 8271e32..cf162e4 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -406,9 +406,6 @@ BOOL freerdp_check_event_handles(rdpContext* context) return FALSE; } - if (!status) - return FALSE; - status = checkChannelErrorEvent(context); if (!status) diff --git a/libfreerdp/core/gateway/ntlm.c b/libfreerdp/core/gateway/ntlm.c index 98f1b15..0a8152a 100644 --- a/libfreerdp/core/gateway/ntlm.c +++ b/libfreerdp/core/gateway/ntlm.c @@ -220,6 +220,12 @@ BOOL ntlm_authenticate(rdpNtlm* ntlm, BOOL* pbContinueNeeded) { SECURITY_STATUS status; + if ((!ntlm) || (!ntlm->table)) + { + WLog_ERR(TAG, "ntlm_authenticate: invalid ntlm context"); + return FALSE; + } + if (ntlm->outputBuffer[0].pvBuffer) { free(ntlm->outputBuffer[0].pvBuffer); @@ -252,12 +258,6 @@ BOOL ntlm_authenticate(rdpNtlm* ntlm, BOOL* pbContinueNeeded) } } - if ((!ntlm) || (!ntlm->table)) - { - WLog_ERR(TAG, "ntlm_authenticate: invalid ntlm context"); - return FALSE; - } - status = ntlm->table->InitializeSecurityContext(&ntlm->credentials, (ntlm->haveContext) ? &ntlm->context : NULL, (ntlm->ServicePrincipalName) ? ntlm->ServicePrincipalName : NULL, diff --git a/libfreerdp/core/info.c b/libfreerdp/core/info.c index 67a66e7..c2e5b8a 100644 --- a/libfreerdp/core/info.c +++ b/libfreerdp/core/info.c @@ -172,7 +172,7 @@ static BOOL rdp_read_server_auto_reconnect_cookie(rdpRdp* rdp, wStream* s, logon info->LogonId = autoReconnectCookie->logonId; CopyMemory(info->ArcRandomBits, p, 16); - if ((settings->PrintReconnectCookie) && (autoReconnectCookie->cbLen > 0)) + if ((settings->PrintReconnectCookie)) { char* base64; base64 = crypto_base64_encode((BYTE*) autoReconnectCookie, sizeof(ARC_SC_PRIVATE_PACKET)); @@ -777,15 +777,8 @@ static void rdp_write_info_packet(rdpRdp* rdp, wStream* s) /* excludes (!) the length of the mandatory null terminator */ cbDomain = cbDomain >= 2 ? cbDomain - 2 : cbDomain; - if (!settings->RemoteAssistanceMode) - { - cbUserName = ConvertToUnicode(CP_UTF8, 0, settings->Username, -1, &userNameW, 0) * 2; - } - else - { - /* user name provided by the expert for connecting to the novice computer */ - cbUserName = ConvertToUnicode(CP_UTF8, 0, settings->Username, -1, &userNameW, 0) * 2; - } + /* user name provided by the expert for connecting to the novice computer */ + cbUserName = ConvertToUnicode(CP_UTF8, 0, settings->Username, -1, &userNameW, 0) * 2; /* excludes (!) the length of the mandatory null terminator */ cbUserName = cbUserName >= 2 ? cbUserName - 2 : cbUserName; diff --git a/libfreerdp/core/nego.c b/libfreerdp/core/nego.c index cb7fd1c..a0b615c 100644 --- a/libfreerdp/core/nego.c +++ b/libfreerdp/core/nego.c @@ -914,7 +914,7 @@ BOOL nego_send_negotiation_request(rdpNego* nego) length += 8; } - if ((length < 5) || (length > UINT16_MAX)) + if (length > UINT16_MAX) goto fail; em = Stream_GetPosition(s); diff --git a/libfreerdp/core/proxy.c b/libfreerdp/core/proxy.c index c1ea49c..029b794 100644 --- a/libfreerdp/core/proxy.c +++ b/libfreerdp/core/proxy.c @@ -490,9 +490,10 @@ static int recv_socks_reply(BIO* bufferedBio, BYTE* buf, int len, char* reason, status = BIO_read(bufferedBio, buf, len); if (status > 0) + { break; - - if (status < 0) + } + else if (status < 0) { /* Error? */ if (BIO_should_retry(bufferedBio)) @@ -504,8 +505,7 @@ static int recv_socks_reply(BIO* bufferedBio, BYTE* buf, int len, char* reason, WLog_ERR(TAG, "Failed reading %s reply from SOCKS proxy (Status %d)", reason, status); return -1; } - - if (status == 0) + else // if (status == 0) { /* Error? */ WLog_ERR(TAG, "Failed reading %s reply from SOCKS proxy (BIO_read returned zero)", reason); diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index c421edd..049700f 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -562,7 +562,7 @@ SSIZE_T transport_read_layer(rdpTransport* transport, BYTE* data, size_t bytes) { const SSIZE_T tr = (SSIZE_T)bytes - read; int r = (int)((tr > INT_MAX) ? INT_MAX : tr); - int status = status = BIO_read(transport->frontBio, data + read, r); + int status = BIO_read(transport->frontBio, data + read, r); if (status <= 0) { diff --git a/libfreerdp/crypto/certificate.c b/libfreerdp/crypto/certificate.c index ad8fd67..a222754 100644 --- a/libfreerdp/crypto/certificate.c +++ b/libfreerdp/crypto/certificate.c @@ -68,10 +68,7 @@ static BOOL certificate_line_is_comment(const char* line, size_t length) } } - if (length < 1) - return TRUE; - - return FALSE; + return TRUE; } BOOL certificate_store_init(rdpCertificateStore* certificate_store) diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index 4bb2c3e..4a393c3 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -546,7 +546,6 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, RDPGFX_H264_METABLOCK* meta1; RDPGFX_AVC420_BITMAP_STREAM* avc2; RDPGFX_H264_METABLOCK* meta2; - RECTANGLE_16* regionRects = NULL; surface = (gdiGfxSurface*) context->GetSurfaceData(context, cmd->surfaceId); if (!surface) @@ -626,7 +625,6 @@ static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context, } fail: - free(regionRects); return status; #else return ERROR_NOT_SUPPORTED; @@ -880,11 +878,13 @@ static UINT gdi_SurfaceCommand(RdpgfxClientContext* context, const RDPGFX_SURFACE_COMMAND* cmd) { UINT status = CHANNEL_RC_OK; - rdpGdi* gdi = (rdpGdi*) context->custom; + rdpGdi* gdi; if (!context || !cmd) return ERROR_INVALID_PARAMETER; + gdi = (rdpGdi*) context->custom; + EnterCriticalSection(&context->mux); WLog_Print(gdi->log, WLOG_TRACE, "surfaceId=%"PRIu32", codec=%"PRIu32", contextId=%"PRIu32", format=%s, " @@ -998,7 +998,7 @@ static UINT gdi_CreateSurface(RdpgfxClientContext* context, default: free(surface); - return ERROR_INTERNAL_ERROR; + goto fail; } surface->scanline = gfx_align_scanline(surface->width * 4, 16); diff --git a/winpr/libwinpr/comm/comm_serial_sys.c b/winpr/libwinpr/comm/comm_serial_sys.c index 2dff3f2..be5443f 100644 --- a/winpr/libwinpr/comm/comm_serial_sys.c +++ b/winpr/libwinpr/comm/comm_serial_sys.c @@ -1462,13 +1462,6 @@ static BOOL _wait_on_mask(WINPR_COMM *pComm, ULONG *pOutputMask) Sleep(100); /* 100 ms */ } - - CommLog_Print(WLOG_WARN, "_wait_on_mask, unexpected return, WaitEventMask=0x%08"PRIX32"", pComm->WaitEventMask); - EnterCriticalSection(&pComm->EventsLock); - pComm->PendingEvents &= ~SERIAL_EV_FREERDP_WAITING; - LeaveCriticalSection(&pComm->EventsLock); - assert(FALSE); - return FALSE; } static BOOL _set_break_on(WINPR_COMM *pComm) diff --git a/winpr/libwinpr/environment/environment.c b/winpr/libwinpr/environment/environment.c index 0fef75f..d271ce4 100644 --- a/winpr/libwinpr/environment/environment.c +++ b/winpr/libwinpr/environment/environment.c @@ -81,6 +81,7 @@ DWORD GetCurrentDirectoryA(DWORD nBufferLength, LPSTR lpBuffer) } memcpy(lpBuffer, cwd, length + 1); + free(cwd); return length; }