From fe8e1950aaa157d07839d634e9ed2fde004aedc4 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 01/28] [warnings] fix integer narrowing --- libfreerdp/core/childsession.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libfreerdp/core/childsession.c b/libfreerdp/core/childsession.c index e3408a72b..3fb5854d7 100644 --- a/libfreerdp/core/childsession.c +++ b/libfreerdp/core/childsession.c @@ -76,7 +76,8 @@ static int transport_bio_named_write(BIO* bio, const char* buf, int size) return 0; } - return written; + WINPR_ASSERT(written <= INT32_MAX); + return (int)written; } static BOOL treatReadResult(WINPR_BIO_NAMED* ptr, DWORD readBytes) @@ -221,7 +222,7 @@ static int transport_bio_named_read(BIO* bio, char* buf, int size) if ((size >= 0) && ret) { DataChunk chunks[2] = { 0 }; - int nchunks = ringbuffer_peek(&ptr->readBuffer, chunks, ret); + const int nchunks = ringbuffer_peek(&ptr->readBuffer, chunks, ret); for (int i = 0; i < nchunks; i++) { memcpy(buf, chunks[i].data, chunks[i].size); @@ -230,7 +231,7 @@ static int transport_bio_named_read(BIO* bio, char* buf, int size) ringbuffer_commit_read_bytes(&ptr->readBuffer, ret); - WLog_VRB(TAG, "(%d)=%d nchunks=%d", size, ret, nchunks); + WLog_VRB(TAG, "(%d)=%" PRIdz " nchunks=%d", size, ret, nchunks); } if (!ringbuffer_used(&ptr->readBuffer)) @@ -245,7 +246,8 @@ static int transport_bio_named_read(BIO* bio, char* buf, int size) if (ret <= 0) BIO_set_flags(bio, (BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_READ)); - return ret; + WINPR_ASSERT(ret <= INT32_MAX); + return (int)ret; } static int transport_bio_named_puts(BIO* bio, const char* str) @@ -253,7 +255,7 @@ static int transport_bio_named_puts(BIO* bio, const char* str) WINPR_ASSERT(bio); WINPR_ASSERT(str); - return transport_bio_named_write(bio, str, strlen(str)); + return transport_bio_named_write(bio, str, (int)strnlen(str, INT32_MAX)); } static int transport_bio_named_gets(BIO* bio, char* str, int size) From 2e23ddfc1c969b52381fcd968fade804b61dd8f0 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 02/28] [warnings] fix integer narrowing --- libfreerdp/core/fastpath.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index 04c9589ab..78852d47c 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -1066,9 +1066,12 @@ BOOL fastpath_send_multiple_input_pdu(rdpFastPath* fastpath, wStream* s, size_t if (!security_lock(rdp)) goto fail; - int sec_bytes = fastpath_get_sec_bytes(fastpath->rdp); + const size_t sec_bytes = fastpath_get_sec_bytes(fastpath->rdp); + if (sec_bytes + 3ULL > length) + goto fail; + BYTE* fpInputEvents = Stream_PointerAs(s, BYTE) + sec_bytes; - UINT16 fpInputEvents_length = length - 3 - sec_bytes; + const UINT16 fpInputEvents_length = (UINT16)length - 3 - sec_bytes; WINPR_ASSERT(rdp->settings); if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS) From e878927cd71161afb2ffe92e85bd74a8280b183b Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 03/28] [warnings] fix integer narrowing --- libfreerdp/core/gateway/arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreerdp/core/gateway/arm.c b/libfreerdp/core/gateway/arm.c index 886e3914e..49d0c183a 100644 --- a/libfreerdp/core/gateway/arm.c +++ b/libfreerdp/core/gateway/arm.c @@ -140,7 +140,7 @@ static BOOL arm_tls_connect(rdpArm* arm, rdpTls* tls, int timeout) } tls->hostname = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname); - tls->port = settings->GatewayPort; + tls->port = MIN(UINT16_MAX, settings->GatewayPort); tls->isGatewayTransport = TRUE; status = freerdp_tls_connect(tls, bufferedBio); if (status < 1) @@ -241,7 +241,7 @@ static BOOL arm_send_http_request(rdpArm* arm, rdpTls* tls, const char* method, const size_t sz = Stream_Length(s); if (sz <= INT_MAX) - status = freerdp_tls_write_all(tls, Stream_Buffer(s), (int)sz); + status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); Stream_Free(s, TRUE); if (status >= 0 && content_length > 0 && data) From f9bfaba0d222fb0d3a95cfd42a571b836e06a725 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 04/28] [warnings] fix integer narrowing --- libfreerdp/core/gateway/rdg.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/libfreerdp/core/gateway/rdg.c b/libfreerdp/core/gateway/rdg.c index cd8949883..a58a13448 100644 --- a/libfreerdp/core/gateway/rdg.c +++ b/libfreerdp/core/gateway/rdg.c @@ -1249,7 +1249,7 @@ static BOOL rdg_send_http_request(rdpRdg* rdg, rdpTls* tls, const char* method, sz = Stream_Length(s); if (sz <= INT_MAX) - status = freerdp_tls_write_all(tls, Stream_Buffer(s), (int)sz); + status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); Stream_Free(s, TRUE); return (status >= 0); @@ -1316,7 +1316,7 @@ static BOOL rdg_tls_connect(rdpRdg* rdg, rdpTls* tls, const char* peerAddress, i } tls->hostname = settings->GatewayHostname; - tls->port = (int)settings->GatewayPort; + tls->port = MIN(UINT16_MAX, settings->GatewayPort); tls->isGatewayTransport = TRUE; status = freerdp_tls_connect(tls, bufferedBio); if (status < 1) @@ -1722,13 +1722,7 @@ static int rdg_write_chunked_data_packet(rdpRdg* rdg, const BYTE* buf, int isize Stream_SealLength(sChunk); len = Stream_Length(sChunk); - if (len > INT_MAX) - { - Stream_Free(sChunk, TRUE); - return -1; - } - - status = freerdp_tls_write_all(rdg->tlsIn, Stream_Buffer(sChunk), (int)len); + status = freerdp_tls_write_all(rdg->tlsIn, Stream_Buffer(sChunk), len); Stream_Free(sChunk, TRUE); if (status < 0) From 42d66eaebe551cc8cf860532882178d713183b04 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 05/28] [warnings] fix integer narrowing --- libfreerdp/core/gateway/rpc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libfreerdp/core/gateway/rpc.c b/libfreerdp/core/gateway/rpc.c index fa4733930..d90d80ad7 100644 --- a/libfreerdp/core/gateway/rpc.c +++ b/libfreerdp/core/gateway/rpc.c @@ -483,13 +483,10 @@ SSIZE_T rpc_channel_read(RpcChannel* channel, wStream* s, size_t length) SSIZE_T rpc_channel_write(RpcChannel* channel, const BYTE* data, size_t length) { - int status = 0; - - if (!channel || (length > INT32_MAX)) + if (!channel) return -1; - status = freerdp_tls_write_all(channel->tls, data, (INT32)length); - return status; + return freerdp_tls_write_all(channel->tls, data, length); } BOOL rpc_in_channel_transition_to_state(RpcInChannel* inChannel, CLIENT_IN_CHANNEL_STATE state) @@ -770,7 +767,7 @@ static BOOL rpc_channel_tls_connect(RpcChannel* channel, UINT32 timeout) return FALSE; tls->hostname = settings->GatewayHostname; - tls->port = settings->GatewayPort; + tls->port = MIN(UINT16_MAX, settings->GatewayPort); tls->isGatewayTransport = TRUE; int tlsStatus = freerdp_tls_connect(tls, bufferedBio); From 83921b0f673e2f9a1d8b18d74f3e17c9a6ae8d90 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 06/28] [warnings] fix integer narrowing --- libfreerdp/core/gateway/rpc_client.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libfreerdp/core/gateway/rpc_client.c b/libfreerdp/core/gateway/rpc_client.c index 371684c96..291eadca0 100644 --- a/libfreerdp/core/gateway/rpc_client.c +++ b/libfreerdp/core/gateway/rpc_client.c @@ -1007,7 +1007,9 @@ int rpc_in_channel_send_pdu(RpcInChannel* inChannel, const BYTE* buffer, size_t inChannel->SenderAvailableWindow -= status; } - return status; + if (status > INT32_MAX) + return -1; + return (int)status; } BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum) From 142d112eee96eb602228ef53d1dd23ab178a2b90 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 07/28] [warnings] fix integer narrowing --- libfreerdp/core/gateway/wst.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libfreerdp/core/gateway/wst.c b/libfreerdp/core/gateway/wst.c index d603c8538..b1d3463ba 100644 --- a/libfreerdp/core/gateway/wst.c +++ b/libfreerdp/core/gateway/wst.c @@ -208,7 +208,7 @@ static BOOL wst_recv_auth_token(rdpCredsspAuth* auth, HttpResponse* response) return TRUE; } -static BOOL wst_tls_connect(rdpWst* wst, rdpTls* tls, int timeout) +static BOOL wst_tls_connect(rdpWst* wst, rdpTls* tls, UINT32 timeout) { WINPR_ASSERT(wst); WINPR_ASSERT(tls); @@ -269,7 +269,7 @@ static BOOL wst_tls_connect(rdpWst* wst, rdpTls* tls, int timeout) } tls->hostname = wst->gwhostname; - tls->port = wst->gwport; + tls->port = MIN(UINT16_MAX, wst->gwport); tls->isGatewayTransport = TRUE; status = freerdp_tls_connect(tls, bufferedBio); if (status < 1) @@ -346,7 +346,7 @@ static BOOL wst_send_http_request(rdpWst* wst, rdpTls* tls) sz = Stream_Length(s); if (sz <= INT_MAX) - status = freerdp_tls_write_all(tls, Stream_Buffer(s), (int)sz); + status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); Stream_Free(s, TRUE); return (status >= 0); From afc4f9b92a465eb45c87bf2df2c20893a0b43f80 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 08/28] [warnings] fix integer narrowing --- libfreerdp/core/license.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfreerdp/core/license.c b/libfreerdp/core/license.c index 568f74650..98d921a4b 100644 --- a/libfreerdp/core/license.c +++ b/libfreerdp/core/license.c @@ -1618,7 +1618,7 @@ BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList) Stream_Read_UINT32(s, scopeCount); /* ScopeCount (4 bytes) */ - if (!license_check_stream_length(s, scopeCount * 4ull, "license scope list::count")) + if (!license_check_stream_length(s, 4ll * scopeCount, "license scope list::count")) return FALSE; if (!license_scope_list_resize(scopeList, scopeCount)) From 69b9f81c2939a50013cf7b6bfe5747826fc5978b Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 09/28] [warnings] fix integer narrowing --- libfreerdp/core/proxy.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libfreerdp/core/proxy.c b/libfreerdp/core/proxy.c index 4a3a384e4..6d0b4db11 100644 --- a/libfreerdp/core/proxy.c +++ b/libfreerdp/core/proxy.c @@ -605,7 +605,11 @@ static BOOL http_proxy_connect(rdpContext* context, BIO* bufferedBio, const char Stream_Write(s, CRLF CRLF, 4); ERR_clear_error(); - status = BIO_write(bufferedBio, Stream_Buffer(s), Stream_GetPosition(s)); + const size_t pos = Stream_GetPosition(s); + if (pos > INT32_MAX) + goto fail; + + status = BIO_write(bufferedBio, Stream_Buffer(s), (int)pos); if ((status < 0) || ((size_t)status != Stream_GetPosition(s))) { @@ -623,10 +627,12 @@ static BOOL http_proxy_connect(rdpContext* context, BIO* bufferedBio, const char WLog_ERR(TAG, "HTTP Reply headers too long: %s", get_response_header(recv_buf)); goto fail; } + const size_t rdsize = sizeof(recv_buf) - resultsize - 1ULL; ERR_clear_error(); - status = - BIO_read(bufferedBio, (BYTE*)recv_buf + resultsize, sizeof(recv_buf) - resultsize - 1); + + WINPR_ASSERT(rdsize <= INT32_MAX); + status = BIO_read(bufferedBio, (BYTE*)recv_buf + resultsize, (int)rdsize); if (status < 0) { @@ -762,8 +768,8 @@ static BOOL socks_proxy_connect(rdpContext* context, BIO* bufferedBio, const cha int status = 0; int nauthMethods = 1; int writeLen = 3; - BYTE buf[3 + 255 + 255]; /* biggest packet is user/pass auth */ - size_t hostnlen = strnlen(hostname, 255); + BYTE buf[3 + 255 + 255] = { 0 }; /* biggest packet is user/pass auth */ + const size_t hostnlen = strnlen(hostname, 255); if (proxyUsername && proxyPassword) { @@ -804,8 +810,8 @@ static BOOL socks_proxy_connect(rdpContext* context, BIO* bufferedBio, const cha return FALSE; else { - int usernameLen = strnlen(proxyUsername, 255); - int userpassLen = strnlen(proxyPassword, 255); + const BYTE usernameLen = (BYTE)strnlen(proxyUsername, 255); + const BYTE userpassLen = (BYTE)strnlen(proxyPassword, 255); BYTE* ptr = NULL; if (nauthMethods < 2) @@ -856,13 +862,13 @@ static BOOL socks_proxy_connect(rdpContext* context, BIO* bufferedBio, const cha buf[1] = SOCKS_CMD_CONNECT; /* command */ buf[2] = 0; /* 3rd octet is reserved x00 */ buf[3] = SOCKS_ADDR_FQDN; /* addr.type */ - buf[4] = hostnlen; /* DST.ADDR */ + buf[4] = (BYTE)hostnlen; /* DST.ADDR */ memcpy(buf + 5, hostname, hostnlen); /* follows DST.PORT in netw. format */ buf[hostnlen + 5] = (port >> 8) & 0xff; buf[hostnlen + 6] = port & 0xff; ERR_clear_error(); - status = BIO_write(bufferedBio, buf, hostnlen + 7U); + status = BIO_write(bufferedBio, buf, (int)hostnlen + 7); if ((status < 0) || ((size_t)status != (hostnlen + 7U))) { From eea56dcf60ae23fdb4bde12e035083a53ba75b05 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 10/28] [warnings] fix integer narrowing --- libfreerdp/core/rdstls.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libfreerdp/core/rdstls.c b/libfreerdp/core/rdstls.c index 5384a1e1e..d7fad612f 100644 --- a/libfreerdp/core/rdstls.c +++ b/libfreerdp/core/rdstls.c @@ -972,8 +972,10 @@ static SSIZE_T rdstls_parse_pdu_data_type(wLog* log, UINT16 dataType, wStream* s return 0; Stream_Read_UINT16(s, passwordLength); - return Stream_GetPosition(s) + passwordLength; + if (!Stream_SafeSeek(s, passwordLength)) + return 0; } + break; case RDSTLS_DATA_AUTORECONNECT_COOKIE: { if (Stream_GetRemainingLength(s) < 4) @@ -984,13 +986,19 @@ static SSIZE_T rdstls_parse_pdu_data_type(wLog* log, UINT16 dataType, wStream* s if (Stream_GetRemainingLength(s) < 2) return 0; Stream_Read_UINT16(s, cookieLength); - - return 12u + cookieLength; + if (!Stream_SafeSeek(s, cookieLength)) + return 0; } + break; default: WLog_Print(log, WLOG_ERROR, "invalid RDSLTS dataType"); return -1; } + + const size_t len = Stream_GetPosition(s); + if (len > SSIZE_MAX) + return 0; + return (SSIZE_T)len; } SSIZE_T rdstls_parse_pdu(wLog* log, wStream* stream) From 5e6d0a4183dec4f4ee4f37a46f928a1fa8c11d5c Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 11/28] [warnings] fix integer narrowing --- libfreerdp/core/streamdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfreerdp/core/streamdump.c b/libfreerdp/core/streamdump.c index 3f1068091..12a1fe9ff 100644 --- a/libfreerdp/core/streamdump.c +++ b/libfreerdp/core/streamdump.c @@ -335,7 +335,7 @@ static int stream_dump_replay_transport_read(rdpTransport* transport, wStream* s rdpContext* ctx = transport_get_context(transport); size_t size = 0; - time_t slp = 0; + UINT64 slp = 0; UINT64 ts = 0; UINT32 flags = 0; From 429474cd0f26c835f536942b89fcda71ce89f86b Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:24 +0200 Subject: [PATCH 12/28] [warnings] fix integer narrowing --- libfreerdp/core/transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index e048dfaea..92611d285 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -303,7 +303,7 @@ static BOOL transport_default_connect_tls(rdpTransport* transport) tls->hostname = settings->ServerHostname; tls->serverName = settings->UserSpecifiedServerName; - tls->port = settings->ServerPort; + tls->port = MIN(UINT16_MAX, settings->ServerPort); if (tls->port == 0) tls->port = 3389; From 40ba7aa03afcdf14c208e5eb3c10ef48a255ace4 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 13/28] [warnings] fix integer narrowing --- libfreerdp/core/update.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index adb230caf..05f05fcc6 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -2894,7 +2894,7 @@ update_send_new_or_existing_notification_icons(rdpContext* context, /* Write Hdr */ Stream_Write_UINT8(s, controlFlags); /* Header (1 byte) */ - Stream_Write_INT16(s, orderSize); /* OrderSize (2 bytes) */ + Stream_Write_UINT16(s, orderSize); /* OrderSize (2 bytes) */ Stream_Write_UINT32(s, orderInfo->fieldFlags); /* FieldsPresentFlags (4 bytes) */ Stream_Write_UINT32(s, orderInfo->windowId); /* WindowID (4 bytes) */ Stream_Write_UINT32(s, orderInfo->notifyIconId); /* NotifyIconId (4 bytes) */ From 08afc250a387c5d702d1af43f8862e303d0c72b2 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 14/28] [warnings] fix integer narrowing --- libfreerdp/crypto/base64.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libfreerdp/crypto/base64.c b/libfreerdp/crypto/base64.c index 4e98e2bf6..a6bd33609 100644 --- a/libfreerdp/crypto/base64.c +++ b/libfreerdp/crypto/base64.c @@ -307,10 +307,8 @@ static INLINE char* base64_encode_ex(const BYTE* WINPR_RESTRICT alphabet, BOOL crLf, size_t lineSize) { int c = 0; - const BYTE* q = NULL; - char* p = NULL; char* ret = NULL; - int blocks = 0; + size_t blocks = 0; size_t outLen = (length + 3) * 4 / 3; size_t extra = 0; if (crLf) @@ -320,8 +318,8 @@ static INLINE char* base64_encode_ex(const BYTE* WINPR_RESTRICT alphabet, } size_t outCounter = 0; - q = data; - p = ret = (char*)malloc(outLen + extra + 1ull); + const BYTE* q = data; + BYTE* p = ret = malloc(outLen + extra + 1ull); if (!p) return NULL; @@ -339,7 +337,7 @@ static INLINE char* base64_encode_ex(const BYTE* WINPR_RESTRICT alphabet, /* first treat complete blocks */ blocks = length - (length % 3); - for (int i = 0; i < blocks; i += 3, q += 3) + for (size_t i = 0; i < blocks; i += 3, q += 3) { c = (q[0] << 16) + (q[1] << 8) + q[2]; @@ -414,7 +412,7 @@ static INLINE void* base64_decode(const signed char* WINPR_RESTRICT alphabet, BYTE* data = NULL; size_t nBlocks = 0; size_t outputLen = 0; - int remainder = length % 4; + const size_t remainder = length % 4; if ((pad && remainder > 0) || (remainder == 1)) return NULL; From cdb25ea11b2e597e823f4439655d1afd589d98b8 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 15/28] [warnings] fix integer narrowing --- libfreerdp/gdi/pen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libfreerdp/gdi/pen.c b/libfreerdp/gdi/pen.c index 4d0a3a373..cbd091edc 100644 --- a/libfreerdp/gdi/pen.c +++ b/libfreerdp/gdi/pen.c @@ -52,7 +52,8 @@ HGDI_PEN gdi_CreatePen(UINT32 fnPenStyle, UINT32 nWidth, UINT32 crColor, UINT32 hPen->objectType = GDIOBJECT_PEN; hPen->style = fnPenStyle; hPen->color = crColor; - hPen->width = nWidth; + WINPR_ASSERT(nWidth <= INT32_MAX); + hPen->width = (int)nWidth; hPen->format = format; hPen->palette = palette; return hPen; From efeac25fa9d871c62fd8ed98f9741cf22480ccff Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 16/28] [warnings] fix integer narrowing --- rdtk/librdtk/rdtk_font.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdtk/librdtk/rdtk_font.c b/rdtk/librdtk/rdtk_font.c index 4c7ffd6e3..3340d4607 100644 --- a/rdtk/librdtk/rdtk_font.c +++ b/rdtk/librdtk/rdtk_font.c @@ -429,7 +429,7 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, uint8_t* buffer, si *q = '\0'; errno = 0; { - long val = strtoul(p, NULL, 0); + long val = strtol(p, NULL, 0); if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX)) return -1; From 704597937d0627f55ebd75201b0d3c40888d48db Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 17/28] [warnings] fix integer narrowing --- winpr/libwinpr/sspi/Schannel/schannel_openssl.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/winpr/libwinpr/sspi/Schannel/schannel_openssl.c b/winpr/libwinpr/sspi/Schannel/schannel_openssl.c index 63c17d7e1..8c395aa34 100644 --- a/winpr/libwinpr/sspi/Schannel/schannel_openssl.c +++ b/winpr/libwinpr/sspi/Schannel/schannel_openssl.c @@ -33,6 +33,8 @@ #include #include +#define LIMIT_INTMAX(a) ((a) > INT32_MAX) ? INT32_MAX : (int)(a) + struct S_SCHANNEL_OPENSSL { SSL* ssl; @@ -377,7 +379,8 @@ SECURITY_STATUS schannel_openssl_client_process_tokens(SCHANNEL_OPENSSL* context return SEC_E_INVALID_TOKEN; ERR_clear_error(); - status = BIO_write(context->bioRead, pBuffer->pvBuffer, pBuffer->cbBuffer); + status = + BIO_write(context->bioRead, pBuffer->pvBuffer, LIMIT_INTMAX(pBuffer->cbBuffer)); if (status < 0) return SEC_E_INVALID_TOKEN; } @@ -442,7 +445,7 @@ SECURITY_STATUS schannel_openssl_server_process_tokens(SCHANNEL_OPENSSL* context return SEC_E_INVALID_TOKEN; ERR_clear_error(); - status = BIO_write(context->bioRead, pBuffer->pvBuffer, pBuffer->cbBuffer); + status = BIO_write(context->bioRead, pBuffer->pvBuffer, LIMIT_INTMAX(pBuffer->cbBuffer)); if (status >= 0) status = SSL_accept(context->ssl); @@ -506,7 +509,8 @@ SECURITY_STATUS schannel_openssl_encrypt_message(SCHANNEL_OPENSSL* context, PSec if ((!pStreamHeaderBuffer) || (!pStreamBodyBuffer) || (!pStreamTrailerBuffer)) return SEC_E_INVALID_TOKEN; - status = SSL_write(context->ssl, pStreamBodyBuffer->pvBuffer, pStreamBodyBuffer->cbBuffer); + status = SSL_write(context->ssl, pStreamBodyBuffer->pvBuffer, + LIMIT_INTMAX(pStreamBodyBuffer->cbBuffer)); if (status < 0) { @@ -553,9 +557,9 @@ SECURITY_STATUS schannel_openssl_decrypt_message(SCHANNEL_OPENSSL* context, PSec return SEC_E_INVALID_TOKEN; ERR_clear_error(); - status = BIO_write(context->bioRead, pBuffer->pvBuffer, pBuffer->cbBuffer); + status = BIO_write(context->bioRead, pBuffer->pvBuffer, LIMIT_INTMAX(pBuffer->cbBuffer)); if (status > 0) - status = SSL_read(context->ssl, pBuffer->pvBuffer, pBuffer->cbBuffer); + status = SSL_read(context->ssl, pBuffer->pvBuffer, LIMIT_INTMAX(pBuffer->cbBuffer)); if (status < 0) { From eceab9aedb95cb547151baadd13549626077aad9 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 18/28] [warnings] fix integer narrowing --- winpr/libwinpr/utils/collections/ArrayList.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/winpr/libwinpr/utils/collections/ArrayList.c b/winpr/libwinpr/utils/collections/ArrayList.c index 05d5afb5c..d33ea6cd0 100644 --- a/winpr/libwinpr/utils/collections/ArrayList.c +++ b/winpr/libwinpr/utils/collections/ArrayList.c @@ -236,11 +236,13 @@ static BOOL ArrayList_Shift(wArrayList* arrayList, size_t index, SSIZE_T count) } else if (count < 0) { - INT64 chunk = arrayList->size - index + count; - - if (chunk > 0) + const size_t off = index + (size_t)(-1 * count); + if (off < arrayList->size) + { + const size_t chunk = arrayList->size - off; MoveMemory(&arrayList->array[index], &arrayList->array[index - count], - (size_t)chunk * sizeof(void*)); + chunk * sizeof(void*)); + } arrayList->size += count; } @@ -493,9 +495,12 @@ SSIZE_T ArrayList_LastIndexOf(wArrayList* arrayList, const void* obj, SSIZE_T st if (startIndex < 0) sindex = 0; - cindex = (size_t)count; + cindex = count; if (count < 0) - cindex = arrayList->size; + { + WINPR_ASSERT(arrayList->size <= SSIZE_MAX); + cindex = (SSIZE_T)arrayList->size; + } SSIZE_T index = sindex + cindex; for (; index > sindex; index--) From b19dcf8d68b8faac6f2ca8e7d60b38f11c0ad3a1 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 19/28] [warnings] fix integer narrowing --- winpr/libwinpr/utils/collections/BitStream.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/utils/collections/BitStream.c b/winpr/libwinpr/utils/collections/BitStream.c index e57af947f..e7bcd5b42 100644 --- a/winpr/libwinpr/utils/collections/BitStream.c +++ b/winpr/libwinpr/utils/collections/BitStream.c @@ -106,8 +106,9 @@ void BitDump(const char* tag, UINT32 level, const BYTE* buffer, UINT32 length, U for (; i < length; i += 8) { const char* str = strs[buffer[i / 8]]; - const int nbits = (length - i) > 8 ? 8 : (length - i); - const int rc = _snprintf(&pbuffer[pos], length - pos, "%.*s ", nbits, str); + const DWORD nbits = (length - i) > 8 ? 8 : (length - i); + WINPR_ASSERT(nbits <= INT32_MAX); + const int rc = _snprintf(&pbuffer[pos], length - pos, "%.*s ", (int)nbits, str); if (rc < 0) return; From 57ed259be26603887e4df77724c83032d409f27f Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 20/28] [warnings] fix integer narrowing --- winpr/libwinpr/utils/collections/StreamPool.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/utils/collections/StreamPool.c b/winpr/libwinpr/utils/collections/StreamPool.c index f47c9d5a5..024cc1fec 100644 --- a/winpr/libwinpr/utils/collections/StreamPool.c +++ b/winpr/libwinpr/utils/collections/StreamPool.c @@ -187,7 +187,8 @@ static void StreamPool_ShiftAvailable(wStreamPool* pool, size_t index, INT64 cou wStream* StreamPool_Take(wStreamPool* pool, size_t size) { - SSIZE_T foundIndex = -1; + BOOL found = FALSE; + size_t foundIndex = 0; wStream* s = NULL; StreamPool_Lock(pool); @@ -201,12 +202,13 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size) if (Stream_Capacity(s) >= size) { + found = TRUE; foundIndex = index; break; } } - if (foundIndex < 0) + if (!found) { s = Stream_New(NULL, size); if (!s) From 53497a572d4adc75c698169618a208c43b3d5605 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 21/28] [warnings] fix integer narrowing --- winpr/libwinpr/utils/execinfo/debug.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/winpr/libwinpr/utils/execinfo/debug.c b/winpr/libwinpr/utils/execinfo/debug.c index 9867b9d34..453278439 100644 --- a/winpr/libwinpr/utils/execinfo/debug.c +++ b/winpr/libwinpr/utils/execinfo/debug.c @@ -18,6 +18,7 @@ * limitations under the License. */ +#include #include #include @@ -57,7 +58,8 @@ void* winpr_execinfo_backtrace(DWORD size) return NULL; } - const int rc = backtrace(data->buffer, size); + assert(size <= INT32_MAX); + const int rc = backtrace(data->buffer, (int)size); if (rc < 0) { free(data); @@ -80,7 +82,8 @@ char** winpr_execinfo_backtrace_symbols(void* buffer, size_t* used) if (used) *used = data->used; - return backtrace_symbols(data->buffer, data->used); + assert(data->used < INT32_MAX); + return backtrace_symbols(data->buffer, (int)data->used); } void winpr_execinfo_backtrace_symbols_fd(void* buffer, int fd) @@ -90,5 +93,6 @@ void winpr_execinfo_backtrace_symbols_fd(void* buffer, int fd) if (!data) return; - backtrace_symbols_fd(data->buffer, data->used, fd); + assert(data->used <= INT32_MAX); + backtrace_symbols_fd(data->buffer, (int)data->used, fd); } From 544c6ddce6a3ca14eb4ba5afb02801fe5a335699 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 22/28] [warnings] fix integer narrowing --- winpr/libwinpr/utils/image.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/utils/image.c b/winpr/libwinpr/utils/image.c index 82b144d51..25d9b3227 100644 --- a/winpr/libwinpr/utils/image.c +++ b/winpr/libwinpr/utils/image.c @@ -626,7 +626,8 @@ static void* winpr_convert_to_jpeg(const void* data, size_t size, UINT32 width, cinfo.image_width = width; cinfo.image_height = height; - cinfo.input_components = (bpp + 7) / 8; + WINPR_ASSERT(bpp <= INT32_MAX / 8); + cinfo.input_components = (int)(bpp + 7) / 8; cinfo.in_color_space = (bpp > 24) ? JCS_EXT_BGRA : JCS_EXT_BGR; cinfo.data_precision = 8; @@ -900,7 +901,9 @@ static SSIZE_T save_png_to_buffer(UINT32 bpp, UINT32 width, UINT32 height, const png_free(png_ptr, row_pointers); /* Finish writing. */ - rc = state.size; + if (state.size > SSIZE_MAX) + goto fail; + rc = (SSIZE_T)state.size; *pDstData = state.buffer; fail: png_destroy_write_struct(&png_ptr, &info_ptr); From 04bd097455c9eb17c810029bda8402fb6ec5e5d0 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 14:10:58 +0200 Subject: [PATCH 23/28] [warnings] fix integer narrowing --- libfreerdp/core/gateway/websocket.c | 50 +++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/libfreerdp/core/gateway/websocket.c b/libfreerdp/core/gateway/websocket.c index d0c8a2960..2bfeff5f2 100644 --- a/libfreerdp/core/gateway/websocket.c +++ b/libfreerdp/core/gateway/websocket.c @@ -91,7 +91,9 @@ BOOL websocket_write_wstream(BIO* bio, wStream* sPacket, WEBSOCKET_OPCODE opcode Stream_SealLength(sWS); ERR_clear_error(); - status = BIO_write(bio, Stream_Buffer(sWS), Stream_Length(sWS)); + const size_t size = Stream_Length(sWS); + if (size <= INT32_MAX) + status = BIO_write(bio, Stream_Buffer(sWS), (int)size); Stream_Free(sWS, TRUE); if (status != (SSIZE_T)fullLen) @@ -106,13 +108,17 @@ static int websocket_write_all(BIO* bio, const BYTE* data, size_t length) WINPR_ASSERT(data); size_t offset = 0; + if (length > INT32_MAX) + return -1; + while (offset < length) { ERR_clear_error(); - int status = BIO_write(bio, &data[offset], length - offset); + const size_t diff = length - offset; + int status = BIO_write(bio, &data[offset], (int)diff); if (status > 0) - offset += status; + offset += (size_t)status; else { if (!BIO_should_retry(bio)) @@ -130,7 +136,7 @@ static int websocket_write_all(BIO* bio, const BYTE* data, size_t length) } } - return length; + return (int)length; } int websocket_write(BIO* bio, const BYTE* buf, int isize, WEBSOCKET_OPCODE opcode) @@ -222,10 +228,13 @@ static int websocket_read_data(BIO* bio, BYTE* pBuffer, size_t size, return 0; } + const size_t rlen = + (encodingContext->payloadLength < size ? encodingContext->payloadLength : size); + if (rlen > INT32_MAX) + return -1; + ERR_clear_error(); - status = - BIO_read(bio, pBuffer, - (encodingContext->payloadLength < size ? encodingContext->payloadLength : size)); + status = BIO_read(bio, pBuffer, (int)rlen); if (status <= 0) return status; @@ -285,8 +294,12 @@ static int websocket_read_wstream(BIO* bio, wStream* s, websocket_context* encod return -1; } + const size_t rlen = encodingContext->payloadLength; + if (rlen > INT32_MAX) + return -1; + ERR_clear_error(); - status = BIO_read(bio, Stream_Pointer(s), encodingContext->payloadLength); + status = BIO_read(bio, Stream_Pointer(s), (int)rlen); if (status <= 0) return status; @@ -310,7 +323,6 @@ static BOOL websocket_reply_close(BIO* bio, wStream* s) wStream* closeFrame = NULL; uint16_t maskingKey1 = 0; uint16_t maskingKey2 = 0; - int status = 0; size_t closeDataLen = 0; WINPR_ASSERT(bio); @@ -338,8 +350,14 @@ static BOOL websocket_reply_close(BIO* bio, wStream* s) } Stream_SealLength(closeFrame); - ERR_clear_error(); - status = BIO_write(bio, Stream_Buffer(closeFrame), Stream_Length(closeFrame)); + const size_t rlen = Stream_Length(closeFrame); + + int status = -1; + if (rlen <= INT32_MAX) + { + ERR_clear_error(); + status = BIO_write(bio, Stream_Buffer(closeFrame), (int)rlen); + } Stream_Free(closeFrame, TRUE); /* server MUST close socket now. The server is not allowed anymore to @@ -353,7 +371,6 @@ static BOOL websocket_reply_pong(BIO* bio, wStream* s) { wStream* closeFrame = NULL; uint32_t maskingKey = 0; - int status = 0; WINPR_ASSERT(bio); @@ -370,8 +387,13 @@ static BOOL websocket_reply_pong(BIO* bio, wStream* s) Stream_Write_UINT32(closeFrame, maskingKey); /* dummy masking key. */ Stream_SealLength(closeFrame); - ERR_clear_error(); - status = BIO_write(bio, Stream_Buffer(closeFrame), Stream_Length(closeFrame)); + const size_t rlen = Stream_Length(closeFrame); + int status = -1; + if (rlen <= INT32_MAX) + { + ERR_clear_error(); + status = BIO_write(bio, Stream_Buffer(closeFrame), (int)rlen); + } Stream_Free(closeFrame, TRUE); if (status < 0) From 4b5274c34f7c87def0030611fd6b1c24e4096da3 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 24/28] [warnings] fix integer narrowing --- winpr/libwinpr/comm/comm_io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/winpr/libwinpr/comm/comm_io.c b/winpr/libwinpr/comm/comm_io.c index d1c18c28b..ab83eb13c 100644 --- a/winpr/libwinpr/comm/comm_io.c +++ b/winpr/libwinpr/comm/comm_io.c @@ -75,7 +75,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, COMMTIMEOUTS* pTimeouts = NULL; UCHAR vmin = 0; UCHAR vtime = 0; - ULONGLONG Tmax = 0; + LONGLONG Tmax = 0; struct timeval tmaxTimeout; struct timeval* pTmaxTimeout = NULL; struct termios currentTermios; @@ -184,8 +184,8 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, else { /* Tmax */ - Tmax = 1ull * nNumberOfBytesToRead * pTimeouts->ReadTotalTimeoutMultiplier + - 1ull * pTimeouts->ReadTotalTimeoutConstant; + Tmax = 1ll * nNumberOfBytesToRead * pTimeouts->ReadTotalTimeoutMultiplier + + 1ll * pTimeouts->ReadTotalTimeoutConstant; /* INDEFinitely */ if ((Tmax == 0) && (pTimeouts->ReadIntervalTimeout < MAXULONG) && @@ -404,8 +404,8 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite #endif /* ms */ - ULONGLONG Tmax = 1ull * nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier + - 1ull * pComm->timeouts.WriteTotalTimeoutConstant; + LONGLONG Tmax = 1ll * nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier + + 1ll * pComm->timeouts.WriteTotalTimeoutConstant; /* NB: select() may update the timeout argument to indicate * how much time was left. Keep the timeout variable out of * the while() */ From 4fc2e1bb3e8f837b35e4b8bd1b546e2128d1f6b5 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 13:15:25 +0200 Subject: [PATCH 25/28] [warnings] fix integer narrowing --- winpr/include/winpr/comm.h | 10 +++++----- winpr/libwinpr/comm/comm.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/winpr/include/winpr/comm.h b/winpr/include/winpr/comm.h index a58cc4a71..abae58a39 100644 --- a/winpr/include/winpr/comm.h +++ b/winpr/include/winpr/comm.h @@ -224,11 +224,11 @@ typedef struct BYTE ByteSize; BYTE Parity; BYTE StopBits; - char XonChar; - char XoffChar; - char ErrorChar; - char EofChar; - char EvtChar; + BYTE XonChar; + BYTE XoffChar; + BYTE ErrorChar; + BYTE EofChar; + BYTE EvtChar; WORD wReserved1; } DCB, *LPDCB; diff --git a/winpr/libwinpr/comm/comm.h b/winpr/libwinpr/comm/comm.h index 8f95bdf08..2987276f2 100644 --- a/winpr/libwinpr/comm/comm.h +++ b/winpr/libwinpr/comm/comm.h @@ -75,7 +75,7 @@ struct winpr_comm ULONG WaitEventMask; ULONG PendingEvents; - char eventChar; + BYTE eventChar; /* NB: CloseHandle() has to free resources */ }; From 503b9f0bb7ed3339239bb9e7fd9eed7653fba06f Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 14:43:54 +0200 Subject: [PATCH 26/28] [warnings] fix integer narrowing --- libfreerdp/crypto/base64.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libfreerdp/crypto/base64.c b/libfreerdp/crypto/base64.c index a6bd33609..a2a23c41b 100644 --- a/libfreerdp/crypto/base64.c +++ b/libfreerdp/crypto/base64.c @@ -307,7 +307,6 @@ static INLINE char* base64_encode_ex(const BYTE* WINPR_RESTRICT alphabet, BOOL crLf, size_t lineSize) { int c = 0; - char* ret = NULL; size_t blocks = 0; size_t outLen = (length + 3) * 4 / 3; size_t extra = 0; @@ -319,10 +318,12 @@ static INLINE char* base64_encode_ex(const BYTE* WINPR_RESTRICT alphabet, size_t outCounter = 0; const BYTE* q = data; - BYTE* p = ret = malloc(outLen + extra + 1ull); + BYTE* p = malloc(outLen + extra + 1ull); if (!p) return NULL; + char* ret = (char*)p; + /* b1, b2, b3 are input bytes * * 0 1 2 From f00d9c45e0db962aa93e9d2609c037a6f7166966 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 14:48:10 +0200 Subject: [PATCH 27/28] [warnings] fix integer narrowing fix function freerdp_tls_write_all --- libfreerdp/core/gateway/arm.c | 4 +--- libfreerdp/core/gateway/rdg.c | 10 +++------- libfreerdp/core/gateway/wst.c | 12 +++--------- libfreerdp/crypto/tls.c | 22 +++++++++++----------- libfreerdp/crypto/tls.h | 2 +- 5 files changed, 19 insertions(+), 31 deletions(-) diff --git a/libfreerdp/core/gateway/arm.c b/libfreerdp/core/gateway/arm.c index 49d0c183a..55d4186c1 100644 --- a/libfreerdp/core/gateway/arm.c +++ b/libfreerdp/core/gateway/arm.c @@ -239,9 +239,7 @@ static BOOL arm_send_http_request(rdpArm* arm, rdpTls* tls, const char* method, return FALSE; const size_t sz = Stream_Length(s); - - if (sz <= INT_MAX) - status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); + status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); Stream_Free(s, TRUE); if (status >= 0 && content_length > 0 && data) diff --git a/libfreerdp/core/gateway/rdg.c b/libfreerdp/core/gateway/rdg.c index a58a13448..219adaf81 100644 --- a/libfreerdp/core/gateway/rdg.c +++ b/libfreerdp/core/gateway/rdg.c @@ -1238,18 +1238,14 @@ static BOOL rdg_auth_init(rdpRdg* rdg, rdpTls* tls, TCHAR* authPkg) static BOOL rdg_send_http_request(rdpRdg* rdg, rdpTls* tls, const char* method, TRANSFER_ENCODING transferEncoding) { - size_t sz = 0; - wStream* s = NULL; int status = -1; - s = rdg_build_http_request(rdg, method, transferEncoding); + wStream* s = rdg_build_http_request(rdg, method, transferEncoding); if (!s) return FALSE; - sz = Stream_Length(s); - - if (sz <= INT_MAX) - status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); + const size_t sz = Stream_Length(s); + status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); Stream_Free(s, TRUE); return (status >= 0); diff --git a/libfreerdp/core/gateway/wst.c b/libfreerdp/core/gateway/wst.c index b1d3463ba..2c4430cda 100644 --- a/libfreerdp/core/gateway/wst.c +++ b/libfreerdp/core/gateway/wst.c @@ -332,21 +332,15 @@ out: static BOOL wst_send_http_request(rdpWst* wst, rdpTls* tls) { - size_t sz = 0; - wStream* s = NULL; - int status = -1; WINPR_ASSERT(wst); WINPR_ASSERT(tls); - s = wst_build_http_request(wst); - + wStream* s = wst_build_http_request(wst); if (!s) return FALSE; - sz = Stream_Length(s); - - if (sz <= INT_MAX) - status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); + const size_t sz = Stream_Length(s); + int status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); Stream_Free(s, TRUE); return (status >= 0); diff --git a/libfreerdp/crypto/tls.c b/libfreerdp/crypto/tls.c index 7693aa34f..26fa50832 100644 --- a/libfreerdp/crypto/tls.c +++ b/libfreerdp/crypto/tls.c @@ -1236,22 +1236,22 @@ BOOL freerdp_tls_send_alert(rdpTls* tls) return TRUE; } -int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, int length) +int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, size_t length) { WINPR_ASSERT(tls); - int offset = 0; + size_t offset = 0; BIO* bio = tls->bio; + if (length > INT32_MAX) + return -1; + while (offset < length) { ERR_clear_error(); - const int rc = BIO_write(bio, &data[offset], length - offset); + const int status = BIO_write(bio, &data[offset], (int)(length - offset)); - if (rc < 0) - return rc; - - if (rc > 0) - offset += rc; + if (status > 0) + offset += (size_t)status; else { if (!BIO_should_retry(bio)) @@ -1259,8 +1259,8 @@ int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, int length) if (BIO_write_blocked(bio)) { - const long status = BIO_wait_write(bio, 100); - if (status < 0) + const long rc = BIO_wait_write(bio, 100); + if (rc < 0) return -1; } else if (BIO_read_blocked(bio)) @@ -1270,7 +1270,7 @@ int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, int length) } } - return length; + return (int)length; } int freerdp_tls_set_alert_code(rdpTls* tls, int level, int description) diff --git a/libfreerdp/crypto/tls.h b/libfreerdp/crypto/tls.h index 654249446..99e5224b1 100644 --- a/libfreerdp/crypto/tls.h +++ b/libfreerdp/crypto/tls.h @@ -115,7 +115,7 @@ extern "C" FREERDP_LOCAL BOOL freerdp_tls_send_alert(rdpTls* tls); - FREERDP_LOCAL int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, int length); + FREERDP_LOCAL int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, size_t length); FREERDP_LOCAL int freerdp_tls_set_alert_code(rdpTls* tls, int level, int description); From 140fe9c50f518827508dc5b51240534548940b58 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 3 Oct 2024 14:57:05 +0200 Subject: [PATCH 28/28] [clang-tidy] disable readability-misleading-indentation this only triggers because of some #ifdef and some of our macros. As all the code is clang-formatted anyway the warning is useless. --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index e113cff00..828555003 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -71,6 +71,7 @@ Checks: > -readability-identifier-length, -readability-implicit-bool-conversion, -readability-magic-numbers, + -readability-misleading-indentation, -readability-qualified-auto, -readability-suspicious-call-argument, -readability-uppercase-literal-suffix,