diff --git a/libfreerdp/cache/offscreen.c b/libfreerdp/cache/offscreen.c index d3c85f95d..545735f1a 100644 --- a/libfreerdp/cache/offscreen.c +++ b/libfreerdp/cache/offscreen.c @@ -52,15 +52,11 @@ static BOOL update_gdi_create_offscreen_bitmap(rdpContext* context, const CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap) { - UINT16 index = 0; - rdpBitmap* bitmap = NULL; - rdpCache* cache = NULL; - if (!context || !createOffscreenBitmap || !context->cache) return FALSE; - cache = context->cache; - bitmap = Bitmap_Alloc(context); + rdpCache* cache = context->cache; + rdpBitmap* bitmap = Bitmap_Alloc(context); if (!bitmap) return FALSE; @@ -82,11 +78,14 @@ update_gdi_create_offscreen_bitmap(rdpContext* context, offscreen_cache_put(cache->offscreen, createOffscreenBitmap->id, bitmap); if (cache->offscreen->currentSurface == createOffscreenBitmap->id) - bitmap->SetSurface(context, bitmap, FALSE); + { + if (!bitmap->SetSurface(context, bitmap, FALSE)) + return FALSE; + } for (UINT32 i = 0; i < createOffscreenBitmap->deleteList.cIndices; i++) { - index = createOffscreenBitmap->deleteList.indices[i]; + const UINT16 index = createOffscreenBitmap->deleteList.indices[i]; offscreen_cache_delete(cache->offscreen, index); } @@ -96,20 +95,18 @@ update_gdi_create_offscreen_bitmap(rdpContext* context, static BOOL update_gdi_switch_surface(rdpContext* context, const SWITCH_SURFACE_ORDER* switchSurface) { - rdpCache* cache = NULL; - rdpBitmap* bitmap = NULL; - if (!context || !context->cache || !switchSurface || !context->graphics) return FALSE; - cache = context->cache; - bitmap = context->graphics->Bitmap_Prototype; + rdpCache* cache = context->cache; + rdpBitmap* bitmap = context->graphics->Bitmap_Prototype; if (!bitmap) return FALSE; if (switchSurface->bitmapId == SCREEN_BITMAP_SURFACE) { - bitmap->SetSurface(context, NULL, TRUE); + if (!bitmap->SetSurface(context, NULL, TRUE)) + return FALSE; } else { @@ -118,7 +115,8 @@ static BOOL update_gdi_switch_surface(rdpContext* context, if (bmp == NULL) return FALSE; - bitmap->SetSurface(context, bmp, FALSE); + if (!bitmap->SetSurface(context, bmp, FALSE)) + return FALSE; } cache->offscreen->currentSurface = switchSurface->bitmapId; @@ -179,7 +177,12 @@ void offscreen_cache_delete(rdpOffscreenCache* offscreenCache, UINT32 index) WINPR_ASSERT(offscreenCache->context); /* Ensure that the bitmap is no longer used in GDI */ - IFCALL(prevBitmap->SetSurface, offscreenCache->context, NULL, FALSE); + if (prevBitmap->SetSurface) + { + if (!prevBitmap->SetSurface(offscreenCache->context, NULL, FALSE)) + WLog_WARN(TAG, "prevBitmap->SetSurface failed"); + } + Bitmap_Free(offscreenCache->context, prevBitmap); } diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c index 4eadd73ab..3cb6ee199 100644 --- a/libfreerdp/codec/progressive.c +++ b/libfreerdp/codec/progressive.c @@ -760,7 +760,11 @@ static inline int progressive_rfx_dwt_2d_decode(PROGRESSIVE_CONTEXT* WINPR_RESTR else if (!coeffDiff) memcpy(current, buffer, bsize); else - prims->add_16s_inplace(buffer, current, belements); + { + const pstatus_t rc = prims->add_16s_inplace(buffer, current, belements); + if (rc != PRIMITIVES_SUCCESS) + return -1; + } INT16* temp = (INT16*)BufferPool_Take(progressive->bufferPool, -1); /* DWT buffer */ @@ -787,7 +791,7 @@ static inline void progressive_rfx_decode_block(const primitives_t* prims, if (!shift) return; - prims->lShiftC_16s_inplace(buffer, shift, length); + (void)prims->lShiftC_16s_inplace(buffer, shift, length); } static inline int diff --git a/libfreerdp/codec/rfx_encode.c b/libfreerdp/codec/rfx_encode.c index c56fab416..8a95a4ecc 100644 --- a/libfreerdp/codec/rfx_encode.c +++ b/libfreerdp/codec/rfx_encode.c @@ -254,31 +254,28 @@ static void rfx_encode_component(RFX_CONTEXT* WINPR_RESTRICT context, *size = WINPR_ASSERTING_INT_CAST(uint32_t, rc); } -void rfx_encode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, RFX_TILE* WINPR_RESTRICT tile) +BOOL rfx_encode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, RFX_TILE* WINPR_RESTRICT tile) { + BOOL rc = TRUE; union { const INT16** cpv; INT16** pv; } cnv; - BYTE* pBuffer = NULL; - INT16* pSrcDst[3]; - uint32_t YLen = 0; + INT16* pSrcDst[3] = { 0 }; uint32_t CbLen = 0; uint32_t CrLen = 0; - UINT32* YQuant = NULL; - UINT32* CbQuant = NULL; - UINT32* CrQuant = NULL; primitives_t* prims = primitives_get(); static const prim_size_t roi_64x64 = { 64, 64 }; - if (!(pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1))) - return; + BYTE* pBuffer = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1); + if (!pBuffer) + return FALSE; - YLen = CbLen = CrLen = 0; - YQuant = context->quants + (10ULL * tile->quantIdxY); - CbQuant = context->quants + (10ULL * tile->quantIdxCb); - CrQuant = context->quants + (10ULL * tile->quantIdxCr); + uint32_t YLen = CbLen = CrLen = 0; + UINT32* YQuant = context->quants + (10ULL * tile->quantIdxY); + UINT32* CbQuant = context->quants + (10ULL * tile->quantIdxCb); + UINT32* CrQuant = context->quants + (10ULL * tile->quantIdxCr); pSrcDst[0] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 0ULL) + 16ULL])); /* y_r_buffer */ pSrcDst[1] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 1ULL) + 16ULL])); /* cb_g_buffer */ pSrcDst[2] = (INT16*)((&pBuffer[((8192ULL + 32ULL) * 2ULL) + 16ULL])); /* cr_b_buffer */ @@ -291,8 +288,9 @@ void rfx_encode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, RFX_TILE* WINPR_RESTRIC PROFILER_ENTER(context->priv->prof_rfx_rgb_to_ycbcr) cnv.pv = pSrcDst; - prims->RGBToYCbCr_16s16s_P3P3(cnv.cpv, 64 * sizeof(INT16), pSrcDst, 64 * sizeof(INT16), - &roi_64x64); + if (prims->RGBToYCbCr_16s16s_P3P3(cnv.cpv, 64 * sizeof(INT16), pSrcDst, 64 * sizeof(INT16), + &roi_64x64) != PRIMITIVES_SUCCESS) + rc = FALSE; PROFILER_EXIT(context->priv->prof_rfx_rgb_to_ycbcr) /** * We need to clear the buffers as the RLGR encoder expects it to be initialized to zero. @@ -308,5 +306,7 @@ void rfx_encode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, RFX_TILE* WINPR_RESTRIC tile->CbLen = WINPR_ASSERTING_INT_CAST(UINT16, CbLen); tile->CrLen = WINPR_ASSERTING_INT_CAST(UINT16, CrLen); PROFILER_EXIT(context->priv->prof_rfx_encode_rgb) - BufferPool_Return(context->priv->BufferPool, pBuffer); + if (!BufferPool_Return(context->priv->BufferPool, pBuffer)) + return FALSE; + return rc; } diff --git a/libfreerdp/codec/rfx_encode.h b/libfreerdp/codec/rfx_encode.h index 41d858fc5..3ff75a4ad 100644 --- a/libfreerdp/codec/rfx_encode.h +++ b/libfreerdp/codec/rfx_encode.h @@ -23,7 +23,7 @@ #include #include -FREERDP_LOCAL void rfx_encode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, +FREERDP_LOCAL BOOL rfx_encode_rgb(RFX_CONTEXT* WINPR_RESTRICT context, RFX_TILE* WINPR_RESTRICT tile); #endif /* FREERDP_LIB_CODEC_RFX_ENCODE_H */ diff --git a/libfreerdp/codec/rfx_quantization.c b/libfreerdp/codec/rfx_quantization.c index 6fd474edf..e4576a6bd 100644 --- a/libfreerdp/codec/rfx_quantization.c +++ b/libfreerdp/codec/rfx_quantization.c @@ -51,7 +51,7 @@ static inline void rfx_quantization_decode_block(const primitives_t* WINPR_RESTR if (factor == 0) return; - prims->lShiftC_16s_inplace(buffer, factor, buffer_size); + (void)prims->lShiftC_16s_inplace(buffer, factor, buffer_size); } void rfx_quantization_decode(INT16* WINPR_RESTRICT buffer, const UINT32* WINPR_RESTRICT quantVals) diff --git a/libfreerdp/core/autodetect.c b/libfreerdp/core/autodetect.c index b0cdde9cb..dc60c2fda 100644 --- a/libfreerdp/core/autodetect.c +++ b/libfreerdp/core/autodetect.c @@ -860,8 +860,10 @@ state_run_t autodetect_recv_request_packet(rdpAutoDetect* autodetect, RDP_TRANSP goto fail; } - IFCALL(autodetect->RequestReceived, autodetect, transport, autodetectReqPdu.requestType, - autodetectReqPdu.sequenceNumber); + if (!IFCALLRESULT(TRUE, autodetect->RequestReceived, autodetect, transport, + autodetectReqPdu.requestType, autodetectReqPdu.sequenceNumber)) + goto fail; + switch (autodetectReqPdu.requestType) { case RDP_RTT_REQUEST_TYPE_CONTINUOUS: @@ -981,8 +983,10 @@ state_run_t autodetect_recv_response_packet(rdpAutoDetect* autodetect, RDP_TRANS goto fail; } - IFCALL(autodetect->ResponseReceived, autodetect, transport, autodetectRspPdu.responseType, - autodetectRspPdu.sequenceNumber); + if (!IFCALLRESULT(TRUE, autodetect->ResponseReceived, autodetect, transport, + autodetectRspPdu.responseType, autodetectRspPdu.sequenceNumber)) + goto fail; + switch (autodetectRspPdu.responseType) { case RDP_RTT_RESPONSE_TYPE: diff --git a/libfreerdp/core/info.c b/libfreerdp/core/info.c index cc54aee7b..b4e18ce3f 100644 --- a/libfreerdp/core/info.c +++ b/libfreerdp/core/info.c @@ -1257,7 +1257,13 @@ static BOOL rdp_recv_logon_error_info(rdpRdp* rdp, wStream* s, logon_info_ex* in Stream_Read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */ WLog_DBG(TAG, "LogonErrorInfo: Data: 0x%08" PRIX32 " Type: 0x%08" PRIX32 "", errorNotificationData, errorNotificationType); - IFCALL(instance->LogonErrorInfo, instance, errorNotificationData, errorNotificationType); + if (instance->LogonErrorInfo) + { + const int rc = + instance->LogonErrorInfo(instance, errorNotificationData, errorNotificationType); + if (rc < 0) + return FALSE; + } info->ErrorNotificationType = errorNotificationType; info->ErrorNotificationData = errorNotificationData; return TRUE; diff --git a/libfreerdp/core/peer.c b/libfreerdp/core/peer.c index bf26aab6d..84740832e 100644 --- a/libfreerdp/core/peer.c +++ b/libfreerdp/core/peer.c @@ -407,7 +407,11 @@ static state_run_t peer_recv_data_pdu(freerdp_peer* client, wStream* s, return STATE_RUN_FAILED; Stream_Read_UINT32(s, client->ack_frame_id); - IFCALL(update->SurfaceFrameAcknowledge, update->context, client->ack_frame_id); + if (update->SurfaceFrameAcknowledge) + { + if (!update->SurfaceFrameAcknowledge(update->context, client->ack_frame_id)) + return STATE_RUN_FAILED; + } break; case DATA_PDU_TYPE_REFRESH_RECT: @@ -802,7 +806,11 @@ static state_run_t peer_recv_callback_internal(WINPR_ATTR_UNUSED rdpTransport* t rdpSettings* settings = client->context->settings; WINPR_ASSERT(settings); - IFCALL(client->ReachedState, client, rdp_get_state(rdp)); + if (client->ReachedState) + { + if (!client->ReachedState(client, rdp_get_state(rdp))) + return STATE_RUN_FAILED; + } switch (rdp_get_state(rdp)) { case CONNECTION_STATE_INITIAL: @@ -995,7 +1003,11 @@ static state_run_t peer_recv_callback_internal(WINPR_ATTR_UNUSED rdpTransport* t { MONITOR_DEF* monitors = NULL; - IFCALL(client->AdjustMonitorsLayout, client); + if (client->AdjustMonitorsLayout) + { + if (!client->AdjustMonitorsLayout(client)) + return STATE_RUN_FAILED; + } /* client supports the monitorLayout PDU, let's send him the monitors if any */ ret = STATE_RUN_SUCCESS; diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index decda40e0..3408cab88 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -2011,7 +2011,8 @@ void transport_layer_free(rdpTransportLayer* layer) if (!layer) return; - IFCALL(intern->pub.Close, intern->pub.userContext); + if (intern->pub.Close) + intern->pub.Close(intern->pub.userContext); free(intern->userContextShadowPtr); free(intern); } diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index 86cf974a1..ae57a2f88 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -963,7 +963,11 @@ void update_reset_state(rdpUpdate* update) WINPR_ASSERT(altsec); altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE; - IFCALL(altsec->common.SwitchSurface, update->context, &(altsec->switch_surface)); + if (altsec->common.SwitchSurface) + { + if (!altsec->common.SwitchSurface(update->context, &(altsec->switch_surface))) + WLog_Print(up->log, WLOG_WARN, "altsec->common.SwitchSurface failed"); + } } } @@ -988,9 +992,10 @@ BOOL update_post_connect(rdpUpdate* update) } altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE; - IFCALL(update->altsec->SwitchSurface, update->context, &(altsec->switch_surface)); + const BOOL rc = IFCALLRESULT(TRUE, update->altsec->SwitchSurface, update->context, + &(altsec->switch_surface)); up->initialState = FALSE; - return TRUE; + return rc; } void update_post_disconnect(rdpUpdate* update) diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index d5bb7265e..b2e3c0472 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -1048,8 +1048,9 @@ static BOOL gdi_surface_frame_marker(rdpContext* context, case SURFACECMD_FRAMEACTION_END: if (freerdp_settings_get_uint32(context->settings, FreeRDP_FrameAcknowledge) > 0) { - IFCALL(context->update->SurfaceFrameAcknowledge, context, - surfaceFrameMarker->frameId); + if (!IFCALLRESULT(TRUE, context->update->SurfaceFrameAcknowledge, context, + surfaceFrameMarker->frameId)) + return FALSE; } break; diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index 21b9eb6c3..14893b8be 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -119,11 +119,14 @@ static UINT gdi_ResetGraphics(RdpgfxClientContext* context, if (update) { WINPR_ASSERT(update->DesktopResize); - update->DesktopResize(gdi->context); + if (!update->DesktopResize(gdi->context)) + goto fail; } WINPR_ASSERT(context->GetSurfaceIds); - context->GetSurfaceIds(context, &pSurfaceIds, &count); + rc = context->GetSurfaceIds(context, &pSurfaceIds, &count); + if (rc != CHANNEL_RC_OK) + goto fail; for (UINT32 index = 0; index < count; index++) { @@ -242,20 +245,19 @@ static UINT gdi_WindowUpdate(RdpgfxClientContext* context, gdiGfxSurface* surfac static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context) { UINT16 count = 0; - UINT status = ERROR_INTERNAL_ERROR; UINT16* pSurfaceIds = NULL; - rdpGdi* gdi = NULL; WINPR_ASSERT(context); - gdi = (rdpGdi*)context->custom; + rdpGdi* gdi = (rdpGdi*)context->custom; WINPR_ASSERT(gdi); EnterCriticalSection(&context->mux); WINPR_ASSERT(context->GetSurfaceIds); - context->GetSurfaceIds(context, &pSurfaceIds, &count); - status = CHANNEL_RC_OK; + UINT status = context->GetSurfaceIds(context, &pSurfaceIds, &count); + if (status != CHANNEL_RC_OK) + goto fail; for (UINT32 index = 0; index < count; index++) { @@ -282,6 +284,7 @@ static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context) break; } +fail: free(pSurfaceIds); LeaveCriticalSection(&context->mux); return status; @@ -1442,15 +1445,14 @@ fail: static UINT gdi_SurfaceToCache(RdpgfxClientContext* context, const RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache) { - const RECTANGLE_16* rect = NULL; - gdiGfxSurface* surface = NULL; gdiGfxCacheEntry* cacheEntry = NULL; UINT rc = ERROR_INTERNAL_ERROR; EnterCriticalSection(&context->mux); - rect = &(surfaceToCache->rectSrc); + const RECTANGLE_16* rect = &(surfaceToCache->rectSrc); WINPR_ASSERT(context->GetSurfaceData); - surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId); + gdiGfxSurface* surface = + (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId); if (!surface) goto fail; @@ -1476,7 +1478,9 @@ static UINT gdi_SurfaceToCache(RdpgfxClientContext* context, { RDPGFX_EVICT_CACHE_ENTRY_PDU evict = { surfaceToCache->cacheSlot }; WINPR_ASSERT(context->EvictCacheEntry); - context->EvictCacheEntry(context, &evict); + rc = context->EvictCacheEntry(context, &evict); + if (rc != CHANNEL_RC_OK) + goto fail; } WINPR_ASSERT(context->SetCacheSlotData); diff --git a/libfreerdp/primitives/prim_copy.c b/libfreerdp/primitives/prim_copy.c index 76bd51acf..c552ed78d 100644 --- a/libfreerdp/primitives/prim_copy.c +++ b/libfreerdp/primitives/prim_copy.c @@ -120,7 +120,11 @@ static pstatus_t general_copy_8u_AC4r(const BYTE* WINPR_RESTRICT pSrc, INT32 src { do { - generic->copy(src, dst, WINPR_ASSERTING_INT_CAST(int32_t, rowbytes)); + const pstatus_t rc = + generic->copy(src, dst, WINPR_ASSERTING_INT_CAST(int32_t, rowbytes)); + if (rc != PRIMITIVES_SUCCESS) + return rc; + src += srcStep; dst += dstStep; } while (--height); diff --git a/libfreerdp/primitives/prim_set.c b/libfreerdp/primitives/prim_set.c index bff2f5fb0..42fb2e011 100644 --- a/libfreerdp/primitives/prim_set.c +++ b/libfreerdp/primitives/prim_set.c @@ -44,7 +44,6 @@ static pstatus_t general_set_32s(INT32 val, INT32* WINPR_RESTRICT pDst, UINT32 l INT32* dptr = pDst; size_t span = 0; size_t remaining = 0; - primitives_t* prims = NULL; if (len < 256) { @@ -58,7 +57,7 @@ static pstatus_t general_set_32s(INT32 val, INT32* WINPR_RESTRICT pDst, UINT32 l span = 1; *dptr = val; remaining = len - 1; - prims = primitives_get(); + primitives_t* prims = primitives_get(); while (remaining) { @@ -69,7 +68,9 @@ static pstatus_t general_set_32s(INT32 val, INT32* WINPR_RESTRICT pDst, UINT32 l const size_t s = thiswidth << 2; WINPR_ASSERT(thiswidth <= INT32_MAX); - prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), (INT32)s); + const pstatus_t rc = prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), (INT32)s); + if (rc != PRIMITIVES_SUCCESS) + return rc; remaining -= thiswidth; span <<= 1; } @@ -108,7 +109,10 @@ static pstatus_t general_set_32u(UINT32 val, UINT32* WINPR_RESTRICT pDst, UINT32 const size_t s = thiswidth << 2; WINPR_ASSERT(thiswidth <= INT32_MAX); - prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), (INT32)s); + const pstatus_t rc = prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), (INT32)s); + if (rc != PRIMITIVES_SUCCESS) + return rc; + remaining -= thiswidth; span <<= 1; }