From 6a21bdae3db0eb391729a2a4b4a3cbd7f8d009e4 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 21 Dec 2017 09:34:35 +0100 Subject: [PATCH] Fixed various scanbuild warnings. --- channels/geometry/client/geometry_main.c | 58 +++++++++---------- channels/smartcard/client/smartcard_pack.c | 2 +- client/common/cmdline.c | 13 ++--- libfreerdp/core/certificate.c | 7 ++- winpr/libwinpr/pool/cleanup_group.c | 6 +- winpr/libwinpr/pool/test/TestPoolWork.c | 2 +- .../sspi/test/TestAcquireCredentialsHandle.c | 2 +- .../sspi/test/TestInitializeSecurityContext.c | 2 +- 8 files changed, 46 insertions(+), 46 deletions(-) mode change 100755 => 100644 channels/geometry/client/geometry_main.c diff --git a/channels/geometry/client/geometry_main.c b/channels/geometry/client/geometry_main.c old mode 100755 new mode 100644 index f5a728aad..33a40beb6 --- a/channels/geometry/client/geometry_main.c +++ b/channels/geometry/client/geometry_main.c @@ -67,12 +67,12 @@ struct _GEOMETRY_PLUGIN IWTSListener* listener; GEOMETRY_LISTENER_CALLBACK* listener_callback; - GeometryClientContext *context; + GeometryClientContext* context; }; typedef struct _GEOMETRY_PLUGIN GEOMETRY_PLUGIN; -static UINT32 geometry_read_RGNDATA(wStream *s, UINT32 len, FREERDP_RGNDATA *rgndata) +static UINT32 geometry_read_RGNDATA(wStream* s, UINT32 len, FREERDP_RGNDATA* rgndata) { UINT32 dwSize, iType; INT32 right, bottom; @@ -84,13 +84,17 @@ static UINT32 geometry_read_RGNDATA(wStream *s, UINT32 len, FREERDP_RGNDATA *rgn } Stream_Read_UINT32(s, dwSize); - if (dwSize != 32) { + + if (dwSize != 32) + { WLog_ERR(TAG, "invalid RGNDATA dwSize"); return ERROR_INVALID_DATA; } Stream_Read_UINT32(s, iType); - if (iType != RDH_RECTANGLE) { + + if (iType != RDH_RECTANGLE) + { WLog_ERR(TAG, "iType %"PRIu32" for RGNDATA is not supported", iType); return ERROR_UNSUPPORTED_TYPE; } @@ -101,11 +105,10 @@ static UINT32 geometry_read_RGNDATA(wStream *s, UINT32 len, FREERDP_RGNDATA *rgn Stream_Read_INT32(s, rgndata->boundingRect.y); Stream_Read_INT32(s, right); Stream_Read_INT32(s, bottom); - rgndata->boundingRect.width = right - rgndata->boundingRect.x; rgndata->boundingRect.height = bottom - rgndata->boundingRect.y; - len -= 32; + if (len / (4 * 4) < rgndata->nRectCount) { WLog_ERR(TAG, "not enough data for region rectangles"); @@ -127,7 +130,6 @@ static UINT32 geometry_read_RGNDATA(wStream *s, UINT32 len, FREERDP_RGNDATA *rgn Stream_Read_INT32(s, rgndata->rects[i].y); Stream_Read_INT32(s, right); Stream_Read_INT32(s, bottom); - rgndata->rects[i].width = right - rgndata->rects[i].x; rgndata->rects[i].height = bottom - rgndata->rects[i].y; } @@ -146,11 +148,10 @@ static UINT geometry_recv_pdu(GEOMETRY_CHANNEL_CALLBACK* callback, wStream* s) UINT32 length, cbGeometryBuffer; MAPPED_GEOMETRY_PACKET packet; GEOMETRY_PLUGIN* geometry; - GeometryClientContext *context; + GeometryClientContext* context; UINT ret; - geometry = (GEOMETRY_PLUGIN*) callback->plugin; - context = (GeometryClientContext *)geometry->iface.pInterface; + context = (GeometryClientContext*)geometry->iface.pInterface; if (Stream_GetRemainingLength(s) < 4) { @@ -159,7 +160,8 @@ static UINT geometry_recv_pdu(GEOMETRY_CHANNEL_CALLBACK* callback, wStream* s) } Stream_Read_UINT32(s, length); /* Length (4 bytes) */ - if (length < 73 || Stream_GetRemainingLength(s) < (length-4)) + + if (length < 73 || Stream_GetRemainingLength(s) < (length - 4)) { WLog_ERR(TAG, "invalid packet length"); return ERROR_INVALID_DATA; @@ -170,20 +172,17 @@ static UINT geometry_recv_pdu(GEOMETRY_CHANNEL_CALLBACK* callback, wStream* s) Stream_Read_UINT32(s, packet.updateType); Stream_Seek_UINT32(s); /* flags */ Stream_Read_UINT64(s, packet.topLevelId); - Stream_Read_INT32(s, packet.left); Stream_Read_INT32(s, packet.top); Stream_Read_INT32(s, packet.right); Stream_Read_INT32(s, packet.bottom); - Stream_Read_INT32(s, packet.topLevelLeft); Stream_Read_INT32(s, packet.topLevelTop); Stream_Read_INT32(s, packet.topLevelRight); Stream_Read_INT32(s, packet.topLevelBottom); - Stream_Read_UINT32(s, packet.geometryType); - Stream_Read_UINT32(s, cbGeometryBuffer); + if (Stream_GetRemainingLength(s) < cbGeometryBuffer) { WLog_ERR(TAG, "invalid packet length"); @@ -191,12 +190,16 @@ static UINT geometry_recv_pdu(GEOMETRY_CHANNEL_CALLBACK* callback, wStream* s) } ZeroMemory(&packet.geometry, sizeof(packet.geometry)); + if (cbGeometryBuffer) { ret = geometry_read_RGNDATA(s, cbGeometryBuffer, &packet.geometry); + if (ret != CHANNEL_RC_OK) return ret; } + else + ret = CHANNEL_RC_OK; if (context->MappedGeometryPacket) ret = context->MappedGeometryPacket(context, &packet); @@ -210,10 +213,9 @@ static UINT geometry_recv_pdu(GEOMETRY_CHANNEL_CALLBACK* callback, wStream* s) * * @return 0 on success, otherwise a Win32 error code */ -static UINT geometry_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream *data) +static UINT geometry_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) { GEOMETRY_CHANNEL_CALLBACK* callback = (GEOMETRY_CHANNEL_CALLBACK*) pChannelCallback; - return geometry_recv_pdu(callback, data); } @@ -234,12 +236,11 @@ static UINT geometry_on_close(IWTSVirtualChannelCallback* pChannelCallback) * @return 0 on success, otherwise a Win32 error code */ static UINT geometry_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, - IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, - IWTSVirtualChannelCallback** ppCallback) + IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, + IWTSVirtualChannelCallback** ppCallback) { GEOMETRY_CHANNEL_CALLBACK* callback; GEOMETRY_LISTENER_CALLBACK* listener_callback = (GEOMETRY_LISTENER_CALLBACK*) pListenerCallback; - callback = (GEOMETRY_CHANNEL_CALLBACK*) calloc(1, sizeof(GEOMETRY_CHANNEL_CALLBACK)); if (!callback) @@ -254,9 +255,7 @@ static UINT geometry_on_new_channel_connection(IWTSListenerCallback* pListenerCa callback->channel_mgr = listener_callback->channel_mgr; callback->channel = pChannel; listener_callback->channel_callback = callback; - *ppCallback = (IWTSVirtualChannelCallback*) callback; - return CHANNEL_RC_OK; } @@ -269,8 +268,9 @@ static UINT geometry_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelMa { UINT status; GEOMETRY_PLUGIN* geometry = (GEOMETRY_PLUGIN*) pPlugin; + geometry->listener_callback = (GEOMETRY_LISTENER_CALLBACK*) calloc(1, + sizeof(GEOMETRY_LISTENER_CALLBACK)); - geometry->listener_callback = (GEOMETRY_LISTENER_CALLBACK*) calloc(1, sizeof(GEOMETRY_LISTENER_CALLBACK)); if (!geometry->listener_callback) { WLog_ERR(TAG, "calloc failed!"); @@ -280,12 +280,9 @@ static UINT geometry_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelMa geometry->listener_callback->iface.OnNewChannelConnection = geometry_on_new_channel_connection; geometry->listener_callback->plugin = pPlugin; geometry->listener_callback->channel_mgr = pChannelMgr; - status = pChannelMgr->CreateListener(pChannelMgr, GEOMETRY_DVC_CHANNEL_NAME, 0, - (IWTSListenerCallback*) geometry->listener_callback, &(geometry->listener)); - + (IWTSListenerCallback*) geometry->listener_callback, &(geometry->listener)); geometry->listener->pInterface = geometry->iface.pInterface; - return status; } @@ -324,11 +321,12 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) UINT error = CHANNEL_RC_OK; GEOMETRY_PLUGIN* geometry; GeometryClientContext* context; - geometry = (GEOMETRY_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "geometry"); + if (!geometry) { geometry = (GEOMETRY_PLUGIN*) calloc(1, sizeof(GEOMETRY_PLUGIN)); + if (!geometry) { WLog_ERR(TAG, "calloc failed!"); @@ -339,8 +337,8 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) geometry->iface.Connected = NULL; geometry->iface.Disconnected = NULL; geometry->iface.Terminated = geometry_plugin_terminated; - context = (GeometryClientContext*) calloc(1, sizeof(GeometryClientContext)); + if (!context) { WLog_ERR(TAG, "calloc failed!"); @@ -349,10 +347,8 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) } context->handle = (void*) geometry; - geometry->iface.pInterface = (void*) context; geometry->context = context; - error = pEntryPoints->RegisterPlugin(pEntryPoints, "geometry", (IWTSPlugin*) geometry); } else diff --git a/channels/smartcard/client/smartcard_pack.c b/channels/smartcard/client/smartcard_pack.c index c5d66c18e..b82bc168e 100644 --- a/channels/smartcard/client/smartcard_pack.c +++ b/channels/smartcard/client/smartcard_pack.c @@ -2789,7 +2789,7 @@ LONG smartcard_unpack_locate_cards_by_atr_a_call(SMARTCARD_DEVICE* smartcard, wS if (call->cReaders > 0) { - call->rgReaderStates = (ReaderStateA*)calloc(call->cReaders, sizeof(SCARD_READERSTATEA)); + call->rgReaderStates = (ReaderStateA*)calloc(call->cReaders, sizeof(ReaderStateA)); if (!call->rgReaderStates) { diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 550f5e626..af70abf5e 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -246,10 +246,7 @@ static void freerdp_client_print_command_line_args(COMMAND_LINE_ARGUMENT_A* arg) length += 2; if (length >= 20 + 8 + 8) - { - length += 3 - strlen(arg->Format); overlong = TRUE; - } if (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL) printf("%s[:%s]", arg->Name, overlong ? "..." : arg->Format); @@ -476,7 +473,6 @@ BOOL freerdp_client_add_device_channel(rdpSettings* settings, int count, settings->RedirectSmartCards = TRUE; settings->DeviceRedirection = TRUE; - smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD)); if (!smartcard) @@ -725,7 +721,8 @@ error_argv: return FALSE; } -static char** freerdp_command_line_parse_comma_separated_values_ex(const char* name, const char* list, +static char** freerdp_command_line_parse_comma_separated_values_ex(const char* name, + const char* list, size_t* count) { char** p; @@ -757,7 +754,8 @@ static char** freerdp_command_line_parse_comma_separated_values_ex(const char* n { const char* it = list; - while((it = strchr(it, ',')) != NULL) + + while ((it = strchr(it, ',')) != NULL) { it++; nCommas++; @@ -771,7 +769,7 @@ static char** freerdp_command_line_parse_comma_separated_values_ex(const char* n prefix = (nArgs + 1UL) * sizeof(char*); len = strlen(list); - p = (char**) calloc(len + prefix + 1, sizeof(char)); + p = (char**) calloc(len + prefix + 1, sizeof(char*)); if (!p) return NULL; @@ -1760,6 +1758,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, WLog_ERR(TAG, "Smart sizing and dynamic resolution are mutually exclusive options"); return COMMAND_LINE_ERROR_UNEXPECTED_VALUE; } + settings->SupportDisplayControl = TRUE; settings->DynamicResolutionUpdate = TRUE; } diff --git a/libfreerdp/core/certificate.c b/libfreerdp/core/certificate.c index d0e67c8a8..8fc17194a 100644 --- a/libfreerdp/core/certificate.c +++ b/libfreerdp/core/certificate.c @@ -430,6 +430,10 @@ static BOOL certificate_process_server_public_signature(rdpCertificate* certific #endif Stream_Read(s, encsig, siglen); + + if (siglen < 8) + return FALSE; + /* Last 8 bytes shall be all zero. */ #if defined(CERT_VALIDATE_PADDING) @@ -443,10 +447,9 @@ static BOOL certificate_process_server_public_signature(rdpCertificate* certific } #endif - siglen -= 8; #if defined(CERT_VALIDATE_RSA) - if (crypto_rsa_public_decrypt(encsig, siglen, TSSK_KEY_LENGTH, tssk_modulus, tssk_exponent, + if (crypto_rsa_public_decrypt(encsig, siglen - 8, TSSK_KEY_LENGTH, tssk_modulus, tssk_exponent, sig) <= 0) { WLog_ERR(TAG, "invalid RSA decrypt"); diff --git a/winpr/libwinpr/pool/cleanup_group.c b/winpr/libwinpr/pool/cleanup_group.c index b1e95095a..6bbc8dc65 100644 --- a/winpr/libwinpr/pool/cleanup_group.c +++ b/winpr/libwinpr/pool/cleanup_group.c @@ -80,7 +80,7 @@ PTP_CLEANUP_GROUP winpr_CreateThreadpoolCleanupGroup(void) } VOID winpr_SetThreadpoolCallbackCleanupGroup(PTP_CALLBACK_ENVIRON pcbe, PTP_CLEANUP_GROUP ptpcg, - PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng) + PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng) { pcbe->CleanupGroup = ptpcg; pcbe->CleanupGroupCancelCallback = pfng; @@ -128,7 +128,9 @@ VOID winpr_CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg) if (ptpcg && ptpcg->groups) ArrayList_Free(ptpcg->groups); - ptpcg->env->CleanupGroup = NULL; + if (ptpcg && ptpcg->env) + ptpcg->env->CleanupGroup = NULL; + free(ptpcg); #endif } diff --git a/winpr/libwinpr/pool/test/TestPoolWork.c b/winpr/libwinpr/pool/test/TestPoolWork.c index d032abe0a..10837f99f 100644 --- a/winpr/libwinpr/pool/test/TestPoolWork.c +++ b/winpr/libwinpr/pool/test/TestPoolWork.c @@ -58,7 +58,7 @@ static BOOL test2(void) int index; PTP_POOL pool; PTP_WORK work; - PTP_CLEANUP_GROUP cleanupGroup; + PTP_CLEANUP_GROUP cleanupGroup = NULL; TP_CALLBACK_ENVIRON environment; printf("Private Thread Pool\n"); diff --git a/winpr/libwinpr/sspi/test/TestAcquireCredentialsHandle.c b/winpr/libwinpr/sspi/test/TestAcquireCredentialsHandle.c index b4c5975b6..626b6a8ea 100644 --- a/winpr/libwinpr/sspi/test/TestAcquireCredentialsHandle.c +++ b/winpr/libwinpr/sspi/test/TestAcquireCredentialsHandle.c @@ -12,7 +12,7 @@ int TestAcquireCredentialsHandle(int argc, char* argv[]) { int rc = -1; SECURITY_STATUS status; - CredHandle credentials; + CredHandle credentials = { 0 }; TimeStamp expiration; SEC_WINNT_AUTH_IDENTITY identity; SecurityFunctionTable* table; diff --git a/winpr/libwinpr/sspi/test/TestInitializeSecurityContext.c b/winpr/libwinpr/sspi/test/TestInitializeSecurityContext.c index 3d20c75c3..92261f43e 100644 --- a/winpr/libwinpr/sspi/test/TestInitializeSecurityContext.c +++ b/winpr/libwinpr/sspi/test/TestInitializeSecurityContext.c @@ -17,7 +17,7 @@ int TestInitializeSecurityContext(int argc, char* argv[]) CtxtHandle context; ULONG pfContextAttr; SECURITY_STATUS status; - CredHandle credentials; + CredHandle credentials = { 0 }; TimeStamp expiration; PSecPkgInfo pPackageInfo; SEC_WINNT_AUTH_IDENTITY identity = { 0 };