From 6fb3120c0bd0b9147366a07f0b6ad3de60e59cda Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 17 Sep 2024 13:43:02 +0200 Subject: [PATCH 1/2] [clang-tidy] disable modernize-avoid-c-arrays same as with similar hicpp and cppcoreguidelines check disable for our project --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index e746ac41d..7f9d19468 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -61,6 +61,7 @@ Checks: > -modernize-return-braced-init-list, -modernize-macro-to-enum, -modernize-pass-by-value, + -modernize-avoid-c-arrays, -readability-braces-around-statements, -readability-function-cognitive-complexity, -readability-identifier-length, From 586f40631fc59fc65800b402b70339d41522d898 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 17 Sep 2024 13:19:31 +0200 Subject: [PATCH 2/2] [warnings] fix shorten-64-to-32 --- channels/audin/client/audin_main.c | 4 +- channels/audin/client/pulse/audin_pulse.c | 4 +- channels/cliprdr/cliprdr_common.c | 7 +- channels/disp/server/disp_main.c | 17 ++++- channels/drive/client/drive_main.c | 15 ++-- channels/encomsp/server/encomsp_main.c | 6 +- channels/location/client/location_main.c | 7 +- channels/location/server/location_main.c | 7 +- channels/parallel/client/parallel_main.c | 4 +- channels/rdpei/server/rdpei_main.c | 18 ++++- channels/rdpemsc/server/mouse_cursor_main.c | 5 +- channels/rdpsnd/client/alsa/rdpsnd_alsa.c | 2 +- .../dialogs/res/sdl2_resource_manager.cpp | 5 +- libfreerdp/core/fastpath.c | 22 +++--- libfreerdp/core/info.c | 43 +++++++----- libfreerdp/core/nego.c | 8 ++- libfreerdp/core/nla.c | 4 +- libfreerdp/core/update.c | 70 +++++++------------ rdtk/librdtk/rdtk_font.c | 4 +- .../modules/bitmap-filter/bitmap-filter.cpp | 4 +- winpr/libwinpr/path/path.c | 3 +- winpr/libwinpr/sysinfo/sysinfo.c | 2 +- winpr/libwinpr/timezone/timezone.c | 2 +- winpr/libwinpr/utils/wlog/PacketMessage.c | 2 +- winpr/libwinpr/winsock/winsock.c | 2 +- 25 files changed, 149 insertions(+), 118 deletions(-) diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index 66a35a3d4..08a670cb9 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -943,10 +943,10 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args) { long val = strtol(arg->Value, NULL, 0); - if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX)) + if ((errno != 0) || (val == 0) || (val > UINT32_MAX)) return FALSE; - audin->fixed_format->nSamplesPerSec = val; + audin->fixed_format->nSamplesPerSec = (UINT32)val; } CommandLineSwitchCase(arg, "channel") { diff --git a/channels/audin/client/pulse/audin_pulse.c b/channels/audin/client/pulse/audin_pulse.c index 0f178f7fe..6855d757f 100644 --- a/channels/audin/client/pulse/audin_pulse.c +++ b/channels/audin/client/pulse/audin_pulse.c @@ -399,7 +399,9 @@ static UINT audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* u buffer_attr.prebuf = (UINT32)-1; buffer_attr.minreq = (UINT32)-1; /* 500ms latency */ - buffer_attr.fragsize = pulse->bytes_per_frame * pulse->frames_per_packet; + const size_t frag = pulse->bytes_per_frame * pulse->frames_per_packet; + WINPR_ASSERT(frag <= UINT32_MAX); + buffer_attr.fragsize = (uint32_t)frag; if (buffer_attr.fragsize % pulse->format.nBlockAlign) buffer_attr.fragsize += diff --git a/channels/cliprdr/cliprdr_common.c b/channels/cliprdr/cliprdr_common.c index 6c726db68..7560f0f32 100644 --- a/channels/cliprdr/cliprdr_common.c +++ b/channels/cliprdr/cliprdr_common.c @@ -403,14 +403,13 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL } else if (!useLongFormatNames) { - const size_t cap = Stream_Capacity(sub1); - formatList->numFormats = (cap / 36ULL); - - if ((36ULL * formatList->numFormats) != cap) + const size_t cap = Stream_Capacity(sub1) / 36ULL; + if (cap > UINT32_MAX) { WLog_ERR(TAG, "Invalid short format list length: %" PRIuz "", cap); return ERROR_INTERNAL_ERROR; } + formatList->numFormats = (UINT32)cap; if (formatList->numFormats) formats = (CLIPRDR_FORMAT*)calloc(formatList->numFormats, sizeof(CLIPRDR_FORMAT)); diff --git a/channels/disp/server/disp_main.c b/channels/disp/server/disp_main.c index 620cf8cd0..31d88bf9b 100644 --- a/channels/disp/server/disp_main.c +++ b/channels/disp/server/disp_main.c @@ -311,7 +311,11 @@ static UINT disp_server_handle_messages(DispServerContext* context) return CHANNEL_RC_NO_MEMORY; } - if (WTSVirtualChannelRead(priv->disp_channel, 0, (PCHAR)Stream_Buffer(s), Stream_Capacity(s), + const size_t cap = Stream_Capacity(s); + if (cap > UINT32_MAX) + return CHANNEL_RC_NO_BUFFER; + + if (WTSVirtualChannelRead(priv->disp_channel, 0, (PCHAR)Stream_Buffer(s), (ULONG)cap, &BytesReturned) == FALSE) { WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); @@ -488,8 +492,15 @@ static UINT disp_server_packet_send(DispServerContext* context, wStream* s) WINPR_ASSERT(context); WINPR_ASSERT(s); - if (!WTSVirtualChannelWrite(context->priv->disp_channel, (PCHAR)Stream_Buffer(s), - Stream_GetPosition(s), &written)) + const size_t pos = Stream_GetPosition(s); + if (pos > UINT32_MAX) + { + ret = ERROR_INTERNAL_ERROR; + goto out; + } + + if (!WTSVirtualChannelWrite(context->priv->disp_channel, (PCHAR)Stream_Buffer(s), pos, + &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); ret = ERROR_INTERNAL_ERROR; diff --git a/channels/drive/client/drive_main.c b/channels/drive/client/drive_main.c index b85fc7e24..de11060ca 100644 --- a/channels/drive/client/drive_main.c +++ b/channels/drive/client/drive_main.c @@ -470,7 +470,10 @@ static UINT drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* const size_t volumeLabelLen = (_wcslen(volumeLabel) + 1) * sizeof(WCHAR); const size_t length = 17ul + volumeLabelLen; - Stream_Write_UINT32(output, length); /* Length */ + if ((length > UINT32_MAX) || (volumeLabelLen > UINT32_MAX)) + return CHANNEL_RC_NO_BUFFER; + + Stream_Write_UINT32(output, (UINT32)length); /* Length */ if (!Stream_EnsureRemainingCapacity(output, length)) { @@ -483,7 +486,7 @@ static UINT drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* Stream_Write_UINT32(output, wfad.ftCreationTime.dwHighDateTime); /* VolumeCreationTime */ Stream_Write_UINT32(output, lpNumberOfFreeClusters & 0xffff); /* VolumeSerialNumber */ - Stream_Write_UINT32(output, volumeLabelLen); /* VolumeLabelLength */ + Stream_Write_UINT32(output, (UINT32)volumeLabelLen); /* VolumeLabelLength */ Stream_Write_UINT8(output, 0); /* SupportsObjects */ /* Reserved(1), MUST NOT be added! */ Stream_Write(output, volumeLabel, volumeLabelLen); /* VolumeLabel (Unicode) */ @@ -513,7 +516,11 @@ static UINT drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* InitializeConstWCharFromUtf8("FAT32", LabelBuffer, ARRAYSIZE(LabelBuffer)); const size_t diskTypeLen = (_wcslen(diskType) + 1) * sizeof(WCHAR); const size_t length = 12ul + diskTypeLen; - Stream_Write_UINT32(output, length); /* Length */ + + if ((length > UINT32_MAX) || (diskTypeLen > UINT32_MAX)) + return CHANNEL_RC_NO_BUFFER; + + Stream_Write_UINT32(output, (UINT32)length); /* Length */ if (!Stream_EnsureRemainingCapacity(output, length)) { @@ -524,7 +531,7 @@ static UINT drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* Stream_Write_UINT32(output, FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK); /* FileSystemAttributes */ Stream_Write_UINT32(output, MAX_PATH); /* MaximumComponentNameLength */ - Stream_Write_UINT32(output, diskTypeLen); /* FileSystemNameLength */ + Stream_Write_UINT32(output, (UINT32)diskTypeLen); /* FileSystemNameLength */ Stream_Write(output, diskType, diskTypeLen); /* FileSystemName (Unicode) */ } break; diff --git a/channels/encomsp/server/encomsp_main.c b/channels/encomsp/server/encomsp_main.c index 2122bcb8f..956d72250 100644 --- a/channels/encomsp/server/encomsp_main.c +++ b/channels/encomsp/server/encomsp_main.c @@ -249,8 +249,10 @@ static DWORD WINAPI encomsp_server_thread(LPVOID arg) break; } - if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0, (PCHAR)Stream_Buffer(s), - Stream_Capacity(s), &BytesReturned)) + const size_t cap = Stream_Capacity(s); + if ((cap > UINT32_MAX) || + !WTSVirtualChannelRead(context->priv->ChannelHandle, 0, (PCHAR)Stream_Buffer(s), + (ULONG)cap, &BytesReturned)) { WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); error = ERROR_INTERNAL_ERROR; diff --git a/channels/location/client/location_main.c b/channels/location/client/location_main.c index e031a976b..e0b3854f5 100644 --- a/channels/location/client/location_main.c +++ b/channels/location/client/location_main.c @@ -99,12 +99,15 @@ static BOOL location_read_server_ready_pdu(LOCATION_CALLBACK* callback, wStream* static UINT location_channel_send(IWTSVirtualChannel* channel, wStream* s) { const size_t len = Stream_GetPosition(s); + if (len > UINT32_MAX) + return ERROR_INTERNAL_ERROR; + Stream_SetPosition(s, 2); - Stream_Write_UINT32(s, len); + Stream_Write_UINT32(s, (UINT32)len); WINPR_ASSERT(channel); WINPR_ASSERT(channel->Write); - return channel->Write(channel, len, Stream_Buffer(s), NULL); + return channel->Write(channel, (UINT32)len, Stream_Buffer(s), NULL); } static UINT location_send_client_ready_pdu(const LOCATION_CALLBACK* callback) diff --git a/channels/location/server/location_main.c b/channels/location/server/location_main.c index 93f8cf339..524b8b219 100644 --- a/channels/location/server/location_main.c +++ b/channels/location/server/location_main.c @@ -541,8 +541,11 @@ static UINT location_server_packet_send(LocationServerContext* context, wStream* WINPR_ASSERT(location); WINPR_ASSERT(s); - if (!WTSVirtualChannelWrite(location->location_channel, (PCHAR)Stream_Buffer(s), - Stream_GetPosition(s), &written)) + const size_t pos = Stream_GetPosition(s); + if (pos > UINT32_MAX) + return ERROR_OUTOFMEMORY; + if (!WTSVirtualChannelWrite(location->location_channel, (PCHAR)Stream_Buffer(s), (ULONG)pos, + &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); error = ERROR_INTERNAL_ERROR; diff --git a/channels/parallel/client/parallel_main.c b/channels/parallel/client/parallel_main.c index c459a77d9..e329b3b9c 100644 --- a/channels/parallel/client/parallel_main.c +++ b/channels/parallel/client/parallel_main.c @@ -169,7 +169,7 @@ static UINT parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) status = read(parallel->file, buffer, Length); - if (status < 0) + if ((status < 0) || (status > UINT32_MAX)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); @@ -178,7 +178,7 @@ static UINT parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) } else { - Length = status; + Length = (UINT32)status; } Stream_Write_UINT32(irp->output, Length); diff --git a/channels/rdpei/server/rdpei_main.c b/channels/rdpei/server/rdpei_main.c index c4d713a5e..948087175 100644 --- a/channels/rdpei/server/rdpei_main.c +++ b/channels/rdpei/server/rdpei_main.c @@ -622,8 +622,12 @@ UINT rdpei_server_send_sc_ready(RdpeiServerContext* context, UINT32 version, UIN if (version >= RDPINPUT_PROTOCOL_V300) Stream_Write_UINT32(priv->outputStream, features); + const size_t pos = Stream_GetPosition(priv->outputStream); + if (pos > UINT32_MAX) + return ERROR_INTERNAL_ERROR; + if (!WTSVirtualChannelWrite(priv->channelHandle, (PCHAR)Stream_Buffer(priv->outputStream), - Stream_GetPosition(priv->outputStream), &written)) + (ULONG)pos, &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); return ERROR_INTERNAL_ERROR; @@ -665,8 +669,12 @@ UINT rdpei_server_suspend(RdpeiServerContext* context) Stream_Write_UINT16(priv->outputStream, EVENTID_SUSPEND_TOUCH); Stream_Write_UINT32(priv->outputStream, RDPINPUT_HEADER_LENGTH); + const size_t pos = Stream_GetPosition(priv->outputStream); + if (pos > UINT32_MAX) + return ERROR_INTERNAL_ERROR; + if (!WTSVirtualChannelWrite(priv->channelHandle, (PCHAR)Stream_Buffer(priv->outputStream), - Stream_GetPosition(priv->outputStream), &written)) + (ULONG)pos, &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); return ERROR_INTERNAL_ERROR; @@ -708,8 +716,12 @@ UINT rdpei_server_resume(RdpeiServerContext* context) Stream_Write_UINT16(priv->outputStream, EVENTID_RESUME_TOUCH); Stream_Write_UINT32(priv->outputStream, RDPINPUT_HEADER_LENGTH); + const size_t pos = Stream_GetPosition(priv->outputStream); + if (pos > UINT32_MAX) + return CHANNEL_RC_NO_BUFFER; + if (!WTSVirtualChannelWrite(priv->channelHandle, (PCHAR)Stream_Buffer(priv->outputStream), - Stream_GetPosition(priv->outputStream), &written)) + (ULONG)pos, &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); return ERROR_INTERNAL_ERROR; diff --git a/channels/rdpemsc/server/mouse_cursor_main.c b/channels/rdpemsc/server/mouse_cursor_main.c index 747bc77ef..f05524e21 100644 --- a/channels/rdpemsc/server/mouse_cursor_main.c +++ b/channels/rdpemsc/server/mouse_cursor_main.c @@ -511,8 +511,11 @@ static UINT mouse_cursor_server_packet_send(MouseCursorServerContext* context, w WINPR_ASSERT(mouse_cursor); WINPR_ASSERT(s); + const size_t pos = Stream_GetPosition(s); + if (pos > UINT32_MAX) + return ERROR_OUTOFMEMORY; if (!WTSVirtualChannelWrite(mouse_cursor->mouse_cursor_channel, (PCHAR)Stream_Buffer(s), - Stream_GetPosition(s), &written)) + (ULONG)pos, &written)) { WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); error = ERROR_INTERNAL_ERROR; diff --git a/channels/rdpsnd/client/alsa/rdpsnd_alsa.c b/channels/rdpsnd/client/alsa/rdpsnd_alsa.c index 93a39ee3b..40432cc4b 100644 --- a/channels/rdpsnd/client/alsa/rdpsnd_alsa.c +++ b/channels/rdpsnd/client/alsa/rdpsnd_alsa.c @@ -455,7 +455,7 @@ static UINT rdpsnd_alsa_play(rdpsndDevicePlugin* device, const BYTE* data, size_ int rc = snd_pcm_avail_delay(alsa->pcm_handle, &available, &delay); if ((rc == 0) && (available == 0)) /* Get [ms] from number of samples */ - latency = delay * 1000 / alsa->actual_rate; + latency = (UINT32)MIN(UINT32_MAX, delay * 1000 / alsa->actual_rate); } return latency + alsa->latency; diff --git a/client/SDL/SDL2/dialogs/res/sdl2_resource_manager.cpp b/client/SDL/SDL2/dialogs/res/sdl2_resource_manager.cpp index fe8e99719..ae7c07597 100644 --- a/client/SDL/SDL2/dialogs/res/sdl2_resource_manager.cpp +++ b/client/SDL/SDL2/dialogs/res/sdl2_resource_manager.cpp @@ -26,7 +26,10 @@ SDL_RWops* SDL2ResourceManager::get(const std::string& type, const std::string& if (!d) return nullptr; - return SDL_RWFromConstMem(d->data(), d->size()); + auto s = d->size(); + if (s > INT32_MAX) + return nullptr; + return SDL_RWFromConstMem(d->data(), static_cast(s)); } auto name = filename(type, id); diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index 5809a6f6e..04c9589ab 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -1163,8 +1163,6 @@ wStream* fastpath_update_pdu_init_new(rdpFastPath* fastpath) BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s, BOOL skipCompression) { - UINT16 maxLength = 0; - UINT32 totalLength = 0; BOOL status = TRUE; wStream* fs = NULL; rdpSettings* settings = NULL; @@ -1172,7 +1170,6 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s UINT32 fpHeaderSize = 6; UINT32 fpUpdatePduHeaderSize = 0; UINT32 fpUpdateHeaderSize = 0; - UINT32 CompressionMaxSize = 0; FASTPATH_UPDATE_PDU_HEADER fpUpdatePduHeader = { 0 }; FASTPATH_UPDATE_HEADER fpUpdateHeader = { 0 }; @@ -1186,16 +1183,17 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s if (!settings) return FALSE; - maxLength = FASTPATH_MAX_PACKET_SIZE - 20; + UINT16 maxLength = FASTPATH_MAX_PACKET_SIZE - 20; if (settings->CompressionEnabled && !skipCompression) { - CompressionMaxSize = bulk_compression_max_size(rdp->bulk); - maxLength = (maxLength < CompressionMaxSize) ? maxLength : CompressionMaxSize; + const UINT32 CompressionMaxSize = bulk_compression_max_size(rdp->bulk); + maxLength = + (maxLength < CompressionMaxSize) ? maxLength : MIN(CompressionMaxSize, UINT16_MAX); maxLength -= 20; } - totalLength = Stream_GetPosition(s); + size_t totalLength = Stream_GetPosition(s); Stream_SetPosition(s, 0); /* check if fast path output is possible */ @@ -1209,7 +1207,7 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s if (totalLength > settings->MultifragMaxRequestSize) { WLog_ERR(TAG, - "fast path update size (%" PRIu32 + "fast path update size (%" PRIuz ") exceeds the client's maximum request size (%" PRIu32 ")", totalLength, settings->MultifragMaxRequestSize); return FALSE; @@ -1225,8 +1223,6 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s for (int fragment = 0; (totalLength > 0) || (fragment == 0); fragment++) { - const BYTE* pSrcData = NULL; - UINT32 SrcSize = 0; UINT32 DstSize = 0; const BYTE* pDstData = NULL; UINT32 compressionFlags = 0; @@ -1237,9 +1233,9 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s fpUpdateHeader.compression = 0; fpUpdateHeader.compressionFlags = 0; fpUpdateHeader.updateCode = updateCode; - fpUpdateHeader.size = (totalLength > maxLength) ? maxLength : totalLength; - pSrcData = Stream_Pointer(s); - SrcSize = DstSize = fpUpdateHeader.size; + fpUpdateHeader.size = (UINT16)(totalLength > maxLength) ? maxLength : totalLength; + const BYTE* pSrcData = Stream_Pointer(s); + UINT32 SrcSize = DstSize = fpUpdateHeader.size; if (rdp->sec_flags & SEC_ENCRYPT) fpUpdatePduHeader.secFlags |= FASTPATH_OUTPUT_ENCRYPTED; diff --git a/libfreerdp/core/info.c b/libfreerdp/core/info.c index ccdb7bbf6..579a95c5a 100644 --- a/libfreerdp/core/info.c +++ b/libfreerdp/core/info.c @@ -1393,32 +1393,43 @@ static BOOL rdp_write_logon_info_v1(wStream* s, logon_info* info) const size_t userCharLen = 512 / sizeof(WCHAR); size_t sz = 4 + 52 + 4 + 512 + 4; - size_t len = 0; if (!Stream_EnsureRemainingCapacity(s, sz)) return FALSE; /* domain */ - WINPR_ASSERT(info); - if (!info->domain || !info->username) - return FALSE; + { + WINPR_ASSERT(info); + if (!info->domain || !info->username) + return FALSE; + const size_t len = strnlen(info->domain, charLen + 1); + if (len > charLen) + return FALSE; - len = strnlen(info->domain, charLen + 1); - if (len > charLen) - return FALSE; + const size_t wlen = len * sizeof(WCHAR); + if (wlen > UINT32_MAX) + return FALSE; - Stream_Write_UINT32(s, len * sizeof(WCHAR)); - if (Stream_Write_UTF16_String_From_UTF8(s, charLen, info->domain, len, TRUE) < 0) - return FALSE; + Stream_Write_UINT32(s, (UINT32)wlen); + if (Stream_Write_UTF16_String_From_UTF8(s, charLen, info->domain, len, TRUE) < 0) + return FALSE; + } /* username */ - len = strnlen(info->username, userCharLen + 1); - if (len > userCharLen) - return FALSE; + { + const size_t len = strnlen(info->username, userCharLen + 1); + if (len > userCharLen) + return FALSE; - Stream_Write_UINT32(s, len * sizeof(WCHAR)); - if (Stream_Write_UTF16_String_From_UTF8(s, userCharLen, info->username, len, TRUE) < 0) - return FALSE; + const size_t wlen = len * sizeof(WCHAR); + if (wlen > UINT32_MAX) + return FALSE; + + Stream_Write_UINT32(s, (UINT32)wlen); + + if (Stream_Write_UTF16_String_From_UTF8(s, userCharLen, info->username, len, TRUE) < 0) + return FALSE; + } /* sessionId */ Stream_Write_UINT32(s, info->sessionId); diff --git a/libfreerdp/core/nego.c b/libfreerdp/core/nego.c index ff0f6466f..61e2079a9 100644 --- a/libfreerdp/core/nego.c +++ b/libfreerdp/core/nego.c @@ -884,7 +884,6 @@ static BOOL nego_read_request_token_or_cookie(rdpNego* nego, wStream* s) * Cookie:[space]mstshash=[ANSISTRING][\x0D\x0A] */ UINT16 crlf = 0; - size_t len = 0; BOOL result = FALSE; BOOL isToken = FALSE; size_t remain = Stream_GetRemainingLength(s); @@ -935,13 +934,16 @@ static BOOL nego_read_request_token_or_cookie(rdpNego* nego, wStream* s) if (crlf == 0x0A0D) { Stream_Rewind(s, 2); - len = Stream_GetPosition(s) - pos; + const size_t len = Stream_GetPosition(s) - pos; Stream_Write_UINT16(s, 0); + if (len > UINT32_MAX) + return FALSE; + if (strnlen(str, len) == len) { if (isToken) - result = nego_set_routing_token(nego, str, len); + result = nego_set_routing_token(nego, str, (UINT32)len); else result = nego_set_cookie(nego, str); } diff --git a/libfreerdp/core/nla.c b/libfreerdp/core/nla.c index 9235e80be..11b70ef0c 100644 --- a/libfreerdp/core/nla.c +++ b/libfreerdp/core/nla.c @@ -315,7 +315,7 @@ static BOOL nla_client_setup_identity(rdpNla* nla) WINPR_SAM* sam = SamOpen(NULL, TRUE); if (sam) { - const size_t userLength = strlen(settings->Username); + const UINT32 userLength = (UINT32)strnlen(settings->Username, INT32_MAX); WINPR_SAM_ENTRY* entry = SamLookupUserA( sam, settings->Username, userLength + 1 /* ensure '\0' is checked too */, NULL, 0); if (entry) @@ -1571,7 +1571,7 @@ static BOOL nla_encode_ts_credentials(rdpNla* nla) size_t len = 0; octet_string.data = (BYTE*)freerdp_settings_get_string_as_utf16( - settings, cspData_fields[i].setting_id, &len); + settings, (FreeRDP_Settings_Keys_String)cspData_fields[i].setting_id, &len); octet_string.len = len * sizeof(WCHAR); if (octet_string.len) { diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index 615179672..adb230caf 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -1531,27 +1531,22 @@ static BOOL update_send_play_sound(rdpContext* context, const PLAY_SOUND_UPDATE* static BOOL update_send_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt) { - wStream* s = NULL; - size_t offset = 0; - UINT32 headerLength = 0; - ORDER_INFO orderInfo; - int inf = 0; - rdp_update_internal* update = NULL; + ORDER_INFO orderInfo = { 0 }; WINPR_ASSERT(context); WINPR_ASSERT(dstblt); - update = update_cast(context->update); + rdp_update_internal* update = update_cast(context->update); - headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_DSTBLT); - inf = update_approximate_dstblt_order(&orderInfo, dstblt); + const int headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_DSTBLT); + const size_t inf = update_approximate_dstblt_order(&orderInfo, dstblt); update_check_flush(context, headerLength + inf); - s = update->us; + wStream* s = update->us; if (!s) return FALSE; - offset = Stream_GetPosition(s); + const size_t offset = Stream_GetPosition(s); if (!Stream_EnsureRemainingCapacity(s, headerLength)) return FALSE; @@ -1599,26 +1594,21 @@ static BOOL update_send_patblt(rdpContext* context, PATBLT_ORDER* patblt) static BOOL update_send_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt) { - wStream* s = NULL; - UINT32 offset = 0; - UINT32 headerLength = 0; - ORDER_INFO orderInfo; - int inf = 0; - rdp_update_internal* update = NULL; + ORDER_INFO orderInfo = { 0 }; WINPR_ASSERT(context); WINPR_ASSERT(scrblt); - update = update_cast(context->update); + rdp_update_internal* update = update_cast(context->update); - headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_SCRBLT); - inf = update_approximate_scrblt_order(&orderInfo, scrblt); + const int headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_SCRBLT); + const size_t inf = update_approximate_scrblt_order(&orderInfo, scrblt); update_check_flush(context, headerLength + inf); - s = update->us; + wStream* s = update->us; if (!s) return TRUE; - offset = Stream_GetPosition(s); + const size_t offset = Stream_GetPosition(s); if (!Stream_EnsureRemainingCapacity(s, headerLength)) return FALSE; @@ -1664,25 +1654,20 @@ static BOOL update_send_opaque_rect(rdpContext* context, const OPAQUE_RECT_ORDER static BOOL update_send_line_to(rdpContext* context, const LINE_TO_ORDER* line_to) { - wStream* s = NULL; - int offset = 0; - int headerLength = 0; - ORDER_INFO orderInfo; - int inf = 0; - rdp_update_internal* update = NULL; + ORDER_INFO orderInfo = { 0 }; WINPR_ASSERT(context); WINPR_ASSERT(line_to); - update = update_cast(context->update); - headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_LINE_TO); - inf = update_approximate_line_to_order(&orderInfo, line_to); + rdp_update_internal* update = update_cast(context->update); + const int headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_LINE_TO); + const size_t inf = update_approximate_line_to_order(&orderInfo, line_to); update_check_flush(context, headerLength + inf); - s = update->us; + wStream* s = update->us; if (!s) return FALSE; - offset = Stream_GetPosition(s); + const size_t offset = Stream_GetPosition(s); if (!Stream_EnsureRemainingCapacity(s, headerLength)) return FALSE; @@ -1726,26 +1711,21 @@ static BOOL update_send_memblt(rdpContext* context, MEMBLT_ORDER* memblt) static BOOL update_send_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyph_index) { - wStream* s = NULL; - size_t offset = 0; - int headerLength = 0; - int inf = 0; - ORDER_INFO orderInfo; - rdp_update_internal* update = NULL; + ORDER_INFO orderInfo = { 0 }; WINPR_ASSERT(context); WINPR_ASSERT(glyph_index); - update = update_cast(context->update); + rdp_update_internal* update = update_cast(context->update); - headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_GLYPH_INDEX); - inf = update_approximate_glyph_index_order(&orderInfo, glyph_index); + const int headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_GLYPH_INDEX); + const size_t inf = update_approximate_glyph_index_order(&orderInfo, glyph_index); update_check_flush(context, headerLength + inf); - s = update->us; + wStream* s = update->us; if (!s) return FALSE; - offset = Stream_GetPosition(s); + const size_t offset = Stream_GetPosition(s); if (!Stream_EnsureRemainingCapacity(s, headerLength)) return FALSE; @@ -3309,9 +3289,7 @@ void update_free(rdpUpdate* update) free(altsec); if (update->window) - { free(update->window); - } MessageQueue_Free(up->queue); DeleteCriticalSection(&up->mux); diff --git a/rdtk/librdtk/rdtk_font.c b/rdtk/librdtk/rdtk_font.c index f6603560e..4c7ffd6e3 100644 --- a/rdtk/librdtk/rdtk_font.c +++ b/rdtk/librdtk/rdtk_font.c @@ -277,10 +277,10 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, uint8_t* buffer, si { long val = strtol(p, NULL, 0); - if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX)) + if ((errno != 0) || (val == 0) || (val > UINT32_MAX)) return -1; - font->size = val; + font->size = (UINT32)val; } *q = '"'; diff --git a/server/proxy/modules/bitmap-filter/bitmap-filter.cpp b/server/proxy/modules/bitmap-filter/bitmap-filter.cpp index 48fe36a9f..49542101e 100644 --- a/server/proxy/modules/bitmap-filter/bitmap-filter.cpp +++ b/server/proxy/modules/bitmap-filter/bitmap-filter.cpp @@ -198,7 +198,7 @@ static UINT32 drdynvc_read_variable_uint(wStream* s, UINT8 cbLen) return val; } -static BOOL drdynvc_try_read_header(wStream* s, size_t& channelId, size_t& length) +static BOOL drdynvc_try_read_header(wStream* s, uint32_t& channelId, size_t& length) { UINT8 value = 0; Stream_SetPosition(s, 0); @@ -350,7 +350,7 @@ static BOOL filter_dyn_channel_intercept(proxyPlugin* plugin, proxyData* pdata, { if (data->first) { - size_t channelId = 0; + uint32_t channelId = 0; size_t length = 0; if (drdynvc_try_read_header(data->data, channelId, length)) { diff --git a/winpr/libwinpr/path/path.c b/winpr/libwinpr/path/path.c index 0a8cf1101..3fc9ec6b9 100644 --- a/winpr/libwinpr/path/path.c +++ b/winpr/libwinpr/path/path.c @@ -734,11 +734,10 @@ HRESULT PathCchStripPrefixW(PWSTR pszPath, size_t cchPath) if (hasPrefix) { - int rc = 0; if (cchPath < 6) return S_FALSE; - rc = (_wcslen(&pszPath[4]) + 1); + const size_t rc = (_wcslen(&pszPath[4]) + 1); if ((rc < 0) || ((INT64)cchPath < rc)) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); diff --git a/winpr/libwinpr/sysinfo/sysinfo.c b/winpr/libwinpr/sysinfo/sysinfo.c index 659f79d60..f3cd41795 100644 --- a/winpr/libwinpr/sysinfo/sysinfo.c +++ b/winpr/libwinpr/sysinfo/sysinfo.c @@ -329,7 +329,7 @@ BOOL GetSystemTimeAdjustment(PDWORD lpTimeAdjustment, PDWORD lpTimeIncrement, DWORD GetTickCount(void) { - return GetTickCount64(); + return (DWORD)GetTickCount64(); } #endif // _WIN32 diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index 6c1a02666..3f179f39c 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -729,7 +729,7 @@ static int dynamic_time_zone_from_localtime(const struct tm* local_time, { /* DST bias is the difference between standard time and DST in minutes */ const LONG d = get_bias(local_time, TRUE); - tz->DaylightBias = -1 * labs(tz->Bias - d); + tz->DaylightBias = -1 * (LONG)labs(tz->Bias - d); if (!get_transition_date(local_time, FALSE, &tz->StandardDate)) rc |= HAVE_NO_STANDARD_TRANSITION_DATE; if (!get_transition_date(local_time, TRUE, &tz->DaylightDate)) diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.c b/winpr/libwinpr/utils/wlog/PacketMessage.c index 1bb226ffd..276e4e3a6 100644 --- a/winpr/libwinpr/utils/wlog/PacketMessage.c +++ b/winpr/libwinpr/utils/wlog/PacketMessage.c @@ -457,7 +457,7 @@ BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, size_t length, DWORD flag record.next = NULL; UINT64 ns = winpr_GetUnixTimeNS(); - record.header.ts_sec = WINPR_TIME_NS_TO_S(ns); + record.header.ts_sec = (UINT32)WINPR_TIME_NS_TO_S(ns); record.header.ts_usec = WINPR_TIME_NS_REM_US(ns); if (!Pcap_Write_RecordHeader(pcap, &record.header) || diff --git a/winpr/libwinpr/winsock/winsock.c b/winpr/libwinpr/winsock/winsock.c index 1b053de4c..6cb0c9a0a 100644 --- a/winpr/libwinpr/winsock/winsock.c +++ b/winpr/libwinpr/winsock/winsock.c @@ -761,7 +761,7 @@ int WSAEventSelect(SOCKET s, WSAEVENT hEventObject, LONG lNetworkEvents) if (lNetworkEvents & FD_WRITE) mode |= WINPR_FD_WRITE; - if (SetEventFileDescriptor(hEventObject, s, mode) < 0) + if (SetEventFileDescriptor(hEventObject, (int)s, mode) < 0) return SOCKET_ERROR; return 0;