From b4dab0f419fe65ba4b7b26438bdd8353bdbd9413 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 21 Oct 2024 17:41:20 +0200 Subject: [PATCH 01/15] [warnings] replace getpwnam --- winpr/libwinpr/sspicli/sspicli.c | 36 +++++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/winpr/libwinpr/sspicli/sspicli.c b/winpr/libwinpr/sspicli/sspicli.c index f3e922c70..68524363d 100644 --- a/winpr/libwinpr/sspicli/sspicli.c +++ b/winpr/libwinpr/sspicli/sspicli.c @@ -129,13 +129,10 @@ static HANDLE_OPS ops = { LogonUserIsHandled, BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword, DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken) { - struct passwd* pw = NULL; - WINPR_ACCESS_TOKEN* token = NULL; - if (!lpszUsername) return FALSE; - token = (WINPR_ACCESS_TOKEN*)calloc(1, sizeof(WINPR_ACCESS_TOKEN)); + WINPR_ACCESS_TOKEN* token = (WINPR_ACCESS_TOKEN*)calloc(1, sizeof(WINPR_ACCESS_TOKEN)); if (!token) return FALSE; @@ -145,26 +142,29 @@ BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword, DWO token->Username = _strdup(lpszUsername); if (!token->Username) - { - free(token); - return FALSE; - } + goto fail; if (lpszDomain) { token->Domain = _strdup(lpszDomain); if (!token->Domain) - { - free(token->Username); - free(token); - return FALSE; - } + goto fail; } - pw = getpwnam(lpszUsername); + long buflen = sysconf(_SC_GETPW_R_SIZE_MAX); + if (buflen == -1) + buflen = 8196; - if (pw) + char* buf = (char*)calloc(buflen + 1, sizeof(char)); + if (!buf) + goto fail; + + struct passwd pwd = { 0 }; + struct passwd* pw = NULL; + const int rc = getpwnam_r(lpszUsername, &pwd, buf, buflen, &pw); + free(buf); + if ((rc == 0) && pw) { token->UserId = (DWORD)pw->pw_uid; token->GroupId = (DWORD)pw->pw_gid; @@ -172,6 +172,12 @@ BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword, DWO *((ULONG_PTR*)phToken) = (ULONG_PTR)token; return TRUE; + +fail: + free(token->Username); + free(token->Domain); + free(token); + return FALSE; } BOOL LogonUserW(LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword, DWORD dwLogonType, From fd8947ddc107108efd9b2aed3d840e9bc81e55fd Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 08:55:59 +0200 Subject: [PATCH 02/15] [winpr,kerberos] fix a leak in failure handling --- winpr/libwinpr/sspi/Kerberos/kerberos.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/winpr/libwinpr/sspi/Kerberos/kerberos.c b/winpr/libwinpr/sspi/Kerberos/kerberos.c index bf7d22e54..1c6ea9485 100644 --- a/winpr/libwinpr/sspi/Kerberos/kerberos.c +++ b/winpr/libwinpr/sspi/Kerberos/kerberos.c @@ -693,20 +693,26 @@ static BOOL kerberos_rd_tgt_req_tag2(WinPrAsn1Decoder* dec, char* buf, size_t le BOOL first = TRUE; while (WinPrAsn1DecPeekTag(dec, &tag)) { + BOOL success = FALSE; char* lstr = NULL; if (!WinPrAsn1DecReadGeneralString(dec, &lstr)) - goto end; + goto fail; if (!first) { if (!append(buf, len, "/")) - goto end; + goto fail; } first = FALSE; if (!append(buf, len, lstr)) - goto end; + goto fail; + + success = TRUE; + fail: free(lstr); + if (!success) + goto end; } rc = TRUE; @@ -779,7 +785,6 @@ static BOOL kerberos_rd_tgt_req(WinPrAsn1Decoder* dec, char** target) rc = FALSE; } -end: if (rc) *target = buf; else From 0ace936943d20eb85219b3654264dedeccad47ed Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 21 Oct 2024 18:05:31 +0200 Subject: [PATCH 03/15] [clang-tidy] disable readability-string-compare we have mostly C strings, so c++string.compare(c-string) is to be preferred to c++string == c-string --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index 828555003..5659f8427 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -74,6 +74,7 @@ Checks: > -readability-misleading-indentation, -readability-qualified-auto, -readability-suspicious-call-argument, + -readability-string-compare, -readability-uppercase-literal-suffix, -performance-no-int-to-ptr, -performance-avoid-endl From 4cf5b32733e6b279474fa1e671d7b93d14602fc2 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 21 Oct 2024 17:31:57 +0200 Subject: [PATCH 04/15] [winpr,crypto] prefer inline functions for md5 --- winpr/libwinpr/crypto/md5.c | 103 ++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/winpr/libwinpr/crypto/md5.c b/winpr/libwinpr/crypto/md5.c index f98a54229..04d17f91d 100644 --- a/winpr/libwinpr/crypto/md5.c +++ b/winpr/libwinpr/crypto/md5.c @@ -46,11 +46,26 @@ * architectures that lack an AND-NOT instruction, just like in Colin Plumb's * implementation. */ -#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) -#define H(x, y, z) (((x) ^ (y)) ^ (z)) -#define H2(x, y, z) ((x) ^ ((y) ^ (z))) -#define I(x, y, z) ((y) ^ ((x) | ~(z))) +static inline winpr_MD5_u32plus F(winpr_MD5_u32plus x, winpr_MD5_u32plus y, winpr_MD5_u32plus z) +{ + return ((z) ^ ((x) & ((y) ^ (z)))); +} +static inline winpr_MD5_u32plus G(winpr_MD5_u32plus x, winpr_MD5_u32plus y, winpr_MD5_u32plus z) +{ + return ((y) ^ ((z) & ((x) ^ (y)))); +} +static inline winpr_MD5_u32plus H(winpr_MD5_u32plus x, winpr_MD5_u32plus y, winpr_MD5_u32plus z) +{ + return (((x) ^ (y)) ^ (z)); +} +static inline winpr_MD5_u32plus H2(winpr_MD5_u32plus x, winpr_MD5_u32plus y, winpr_MD5_u32plus z) +{ + return ((x) ^ ((y) ^ (z))); +} +static inline winpr_MD5_u32plus I(winpr_MD5_u32plus x, winpr_MD5_u32plus y, winpr_MD5_u32plus z) +{ + return ((y) ^ ((x) | ~(z))); +} /* * The MD5 transformation for all four rounds. @@ -76,13 +91,14 @@ * their own translation unit avoids the problem. */ #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) -#define SET(n) (*(const winpr_MD5_u32plus*)&ptr[(n)*4]) +#define SET(n) (*(const winpr_MD5_u32plus*)&ptr[4ULL * (n)]) #define GET(n) SET(n) #else -#define SET(n) \ - (ctx->block[(n)] = (winpr_MD5_u32plus)ptr[(n)*4] | ((winpr_MD5_u32plus)ptr[(n)*4 + 1] << 8) | \ - ((winpr_MD5_u32plus)ptr[(n)*4 + 2] << 16) | \ - ((winpr_MD5_u32plus)ptr[(n)*4 + 3] << 24)) +#define SET(n) \ + (ctx->block[(n)] = (winpr_MD5_u32plus)ptr[4ULL * (n)] | \ + ((winpr_MD5_u32plus)ptr[4ULL * (n) + 1] << 8) | \ + ((winpr_MD5_u32plus)ptr[4ULL * (n) + 2] << 16) | \ + ((winpr_MD5_u32plus)ptr[4ULL * (n) + 3] << 24)) #define GET(n) (ctx->block[(n)]) #endif @@ -92,29 +108,19 @@ */ static const void* body(WINPR_MD5_CTX* ctx, const void* data, unsigned long size) { - const unsigned char* ptr = NULL; - winpr_MD5_u32plus a = 0; - winpr_MD5_u32plus b = 0; - winpr_MD5_u32plus c = 0; - winpr_MD5_u32plus d = 0; - winpr_MD5_u32plus saved_a = 0; - winpr_MD5_u32plus saved_b = 0; - winpr_MD5_u32plus saved_c = 0; - winpr_MD5_u32plus saved_d = 0; + const unsigned char* ptr = (const unsigned char*)data; - ptr = (const unsigned char*)data; - - a = ctx->a; - b = ctx->b; - c = ctx->c; - d = ctx->d; + winpr_MD5_u32plus a = ctx->a; + winpr_MD5_u32plus b = ctx->b; + winpr_MD5_u32plus c = ctx->c; + winpr_MD5_u32plus d = ctx->d; do { - saved_a = a; - saved_b = b; - saved_c = c; - saved_d = d; + const winpr_MD5_u32plus saved_a = a; + const winpr_MD5_u32plus saved_b = b; + const winpr_MD5_u32plus saved_c = c; + const winpr_MD5_u32plus saved_d = d; /* Round 1 */ STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7) @@ -217,20 +223,16 @@ void winpr_MD5_Init(WINPR_MD5_CTX* ctx) void winpr_MD5_Update(WINPR_MD5_CTX* ctx, const void* data, unsigned long size) { - winpr_MD5_u32plus saved_lo = 0; - unsigned long used = 0; - unsigned long available = 0; - - saved_lo = ctx->lo; + winpr_MD5_u32plus saved_lo = ctx->lo; if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) ctx->hi++; ctx->hi += size >> 29; - used = saved_lo & 0x3f; + unsigned long used = saved_lo & 0x3f; if (used) { - available = 64 - used; + unsigned long available = 64 - used; if (size < available) { @@ -253,22 +255,21 @@ void winpr_MD5_Update(WINPR_MD5_CTX* ctx, const void* data, unsigned long size) memcpy(ctx->buffer, data, size); } -#define OUT(dst, src) \ - (dst)[0] = (unsigned char)(src); \ - (dst)[1] = (unsigned char)((src) >> 8); \ - (dst)[2] = (unsigned char)((src) >> 16); \ +static inline void OUT(unsigned char* dst, winpr_MD5_u32plus src) +{ + (dst)[0] = (unsigned char)(src); + (dst)[1] = (unsigned char)((src) >> 8); + (dst)[2] = (unsigned char)((src) >> 16); (dst)[3] = (unsigned char)((src) >> 24); +} void winpr_MD5_Final(unsigned char* result, WINPR_MD5_CTX* ctx) { - unsigned long used = 0; - unsigned long available = 0; - - used = ctx->lo & 0x3f; + unsigned long used = ctx->lo & 0x3f; ctx->buffer[used++] = 0x80; - available = 64 - used; + unsigned long available = 64 - used; if (available < 8) { @@ -281,15 +282,15 @@ void winpr_MD5_Final(unsigned char* result, WINPR_MD5_CTX* ctx) memset(&ctx->buffer[used], 0, available - 8); ctx->lo <<= 3; - OUT(&ctx->buffer[56], ctx->lo) - OUT(&ctx->buffer[60], ctx->hi) + OUT(&ctx->buffer[56], ctx->lo); + OUT(&ctx->buffer[60], ctx->hi); body(ctx, ctx->buffer, 64); - OUT(&result[0], ctx->a) - OUT(&result[4], ctx->b) - OUT(&result[8], ctx->c) - OUT(&result[12], ctx->d) + OUT(&result[0], ctx->a); + OUT(&result[4], ctx->b); + OUT(&result[8], ctx->c); + OUT(&result[12], ctx->d); memset(ctx, 0, sizeof(*ctx)); } From 6e3cc23ad207e8e15e24d4b61ab109a77f4a4447 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 09:01:26 +0200 Subject: [PATCH 05/15] [ci] enable WITH_INTERNAL_[RC4|MD4|MD5] test the implementations on qa tester --- ci/cmake-preloads/config-qa.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/cmake-preloads/config-qa.cmake b/ci/cmake-preloads/config-qa.cmake index 3584fb26c..4b5ac5667 100644 --- a/ci/cmake-preloads/config-qa.cmake +++ b/ci/cmake-preloads/config-qa.cmake @@ -20,6 +20,9 @@ set (WITH_SANITIZE_ADDRESS ON CACHE BOOL "qa default") set (WITH_WINPR_UTILS_IMAGE_JPEG ON CACHE BOOL "qa default") set (WITH_WINPR_UTILS_IMAGE_WEBP ON CACHE BOOL "qa default") set (WITH_WINPR_UTILS_IMAGE_PNG ON CACHE BOOL "qa default") +set (WITH_INTERNAL_RC4 ON CACHE BOOL "qa default") +set (WITH_INTERNAL_MD4 ON CACHE BOOL "qa default") +set (WITH_INTERNAL_MD5 ON CACHE BOOL "qa default") set (CHANNEL_RDPECAM ON CACHE BOOL "qa default") set (CHANNEL_RDPECAM_CLIENT ON CACHE BOOL "qa default") set (CHANNEL_RDPEAR ON CACHE BOOL "qa default") From c0a3abfc6214703f6f2b7ea6eb2b055315bf54eb Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 21 Oct 2024 17:06:47 +0200 Subject: [PATCH 06/15] [warnings] duplicate include --- client/X11/xf_keyboard.c | 1 - 1 file changed, 1 deletion(-) diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 6641257e2..27f4e4a16 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include From e41f8eb61fe1347a5792b2ac30947a8ee5d0ca40 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 21 Oct 2024 17:06:23 +0200 Subject: [PATCH 07/15] [warnings] redundant cast --- winpr/libwinpr/thread/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winpr/libwinpr/thread/thread.c b/winpr/libwinpr/thread/thread.c index f1b239f8c..8915012d5 100644 --- a/winpr/libwinpr/thread/thread.c +++ b/winpr/libwinpr/thread/thread.c @@ -576,7 +576,7 @@ static BOOL winpr_StartThread(WINPR_THREAD* thread) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); if (thread->dwStackSize > 0) - pthread_attr_setstacksize(&attr, (size_t)thread->dwStackSize); + pthread_attr_setstacksize(&attr, thread->dwStackSize); thread->started = TRUE; reset_event(thread); From 6929ade1c4daee99c6ee3dfeff80d16b7d239b84 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 09:26:49 +0200 Subject: [PATCH 08/15] [crypto,tls] fix cast --- libfreerdp/crypto/tls.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libfreerdp/crypto/tls.c b/libfreerdp/crypto/tls.c index e80f348bb..dbd60ee56 100644 --- a/libfreerdp/crypto/tls.c +++ b/libfreerdp/crypto/tls.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -902,7 +903,8 @@ TlsHandshakeResult freerdp_tls_connect_ex(rdpTls* tls, BIO* underlying, const SS #if !defined(OPENSSL_NO_TLSEXT) && !defined(LIBRESSL_VERSION_NUMBER) const char* str = tls_get_server_name(tls); - SSL_set_tlsext_host_name(tls->ssl, WINPR_CAST_CONST_PTR_AWAY(str, void*)); + void* ptr = WINPR_CAST_CONST_PTR_AWAY(str, void*); + SSL_set_tlsext_host_name(tls->ssl, ptr); #endif return freerdp_tls_handshake(tls); From b9aa91bfcb5dc6e69af9cbb07c291762a86e1a68 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 09:32:53 +0200 Subject: [PATCH 09/15] [winpr,crypto] use inline functions for md4 --- winpr/libwinpr/crypto/md4.c | 92 ++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/winpr/libwinpr/crypto/md4.c b/winpr/libwinpr/crypto/md4.c index 07438059a..5f5d5f48b 100644 --- a/winpr/libwinpr/crypto/md4.c +++ b/winpr/libwinpr/crypto/md4.c @@ -45,9 +45,18 @@ * F and G are optimized compared to their RFC 1320 definitions, with the * optimization for F borrowed from Colin Plumb's MD5 implementation. */ -#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define G(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) +static inline winpr_MD4_u32plus F(winpr_MD4_u32plus x, winpr_MD4_u32plus y, winpr_MD4_u32plus z) +{ + return ((z) ^ ((x) & ((y) ^ (z)))); +} +static inline winpr_MD4_u32plus G(winpr_MD4_u32plus x, winpr_MD4_u32plus y, winpr_MD4_u32plus z) +{ + return (((x) & ((y) | (z))) | ((y) & (z))); +} +static inline winpr_MD4_u32plus H(winpr_MD4_u32plus x, winpr_MD4_u32plus y, winpr_MD4_u32plus z) +{ + return ((x) ^ (y) ^ (z)); +} /* * The MD4 transformation for all three rounds. @@ -72,13 +81,14 @@ * their own translation unit avoids the problem. */ #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) -#define SET(n) (*(const winpr_MD4_u32plus*)&ptr[(n)*4]) +#define SET(n) (*(const winpr_MD4_u32plus*)&ptr[4ULL * (n)]) #define GET(n) SET(n) #else -#define SET(n) \ - (ctx->block[(n)] = (winpr_MD4_u32plus)ptr[(n)*4] | ((winpr_MD4_u32plus)ptr[(n)*4 + 1] << 8) | \ - ((winpr_MD4_u32plus)ptr[(n)*4 + 2] << 16) | \ - ((winpr_MD4_u32plus)ptr[(n)*4 + 3] << 24)) +#define SET(n) \ + (ctx->block[(n)] = (winpr_MD4_u32plus)ptr[4ULL * (n)] | \ + ((winpr_MD4_u32plus)ptr[4ULL * (n) + 1] << 8) | \ + ((winpr_MD4_u32plus)ptr[4ULL * (n) + 2] << 16) | \ + ((winpr_MD4_u32plus)ptr[4ULL * (n) + 3] << 24)) #define GET(n) (ctx->block[(n)]) #endif @@ -88,31 +98,22 @@ */ static const void* body(WINPR_MD4_CTX* ctx, const void* data, unsigned long size) { - const unsigned char* ptr = NULL; - winpr_MD4_u32plus a = 0; - winpr_MD4_u32plus b = 0; - winpr_MD4_u32plus c = 0; - winpr_MD4_u32plus d = 0; - winpr_MD4_u32plus saved_a = 0; - winpr_MD4_u32plus saved_b = 0; - winpr_MD4_u32plus saved_c = 0; - winpr_MD4_u32plus saved_d = 0; const winpr_MD4_u32plus ac1 = 0x5a827999; const winpr_MD4_u32plus ac2 = 0x6ed9eba1; - ptr = (const unsigned char*)data; + const unsigned char* ptr = (const unsigned char*)data; - a = ctx->a; - b = ctx->b; - c = ctx->c; - d = ctx->d; + winpr_MD4_u32plus a = ctx->a; + winpr_MD4_u32plus b = ctx->b; + winpr_MD4_u32plus c = ctx->c; + winpr_MD4_u32plus d = ctx->d; do { - saved_a = a; - saved_b = b; - saved_c = c; - saved_d = d; + winpr_MD4_u32plus saved_a = a; + winpr_MD4_u32plus saved_b = b; + winpr_MD4_u32plus saved_c = c; + winpr_MD4_u32plus saved_d = d; /* Round 1 */ STEP(F, a, b, c, d, SET(0), 3) @@ -197,20 +198,16 @@ void winpr_MD4_Init(WINPR_MD4_CTX* ctx) void winpr_MD4_Update(WINPR_MD4_CTX* ctx, const void* data, unsigned long size) { - winpr_MD4_u32plus saved_lo = 0; - unsigned long used = 0; - unsigned long available = 0; - - saved_lo = ctx->lo; + winpr_MD4_u32plus saved_lo = ctx->lo; if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) ctx->hi++; ctx->hi += size >> 29; - used = saved_lo & 0x3f; + unsigned long used = saved_lo & 0x3f; if (used) { - available = 64 - used; + unsigned long available = 64 - used; if (size < available) { @@ -233,22 +230,21 @@ void winpr_MD4_Update(WINPR_MD4_CTX* ctx, const void* data, unsigned long size) memcpy(ctx->buffer, data, size); } -#define OUT(dst, src) \ - (dst)[0] = (unsigned char)(src); \ - (dst)[1] = (unsigned char)((src) >> 8); \ - (dst)[2] = (unsigned char)((src) >> 16); \ +static inline void OUT(unsigned char* dst, winpr_MD4_u32plus src) +{ + (dst)[0] = (unsigned char)(src); + (dst)[1] = (unsigned char)((src) >> 8); + (dst)[2] = (unsigned char)((src) >> 16); (dst)[3] = (unsigned char)((src) >> 24); +} void winpr_MD4_Final(unsigned char* result, WINPR_MD4_CTX* ctx) { - unsigned long used = 0; - unsigned long available = 0; - - used = ctx->lo & 0x3f; + unsigned long used = ctx->lo & 0x3f; ctx->buffer[used++] = 0x80; - available = 64 - used; + unsigned long available = 64 - used; if (available < 8) { @@ -261,15 +257,15 @@ void winpr_MD4_Final(unsigned char* result, WINPR_MD4_CTX* ctx) memset(&ctx->buffer[used], 0, available - 8); ctx->lo <<= 3; - OUT(&ctx->buffer[56], ctx->lo) - OUT(&ctx->buffer[60], ctx->hi) + OUT(&ctx->buffer[56], ctx->lo); + OUT(&ctx->buffer[60], ctx->hi); body(ctx, ctx->buffer, 64); - OUT(&result[0], ctx->a) - OUT(&result[4], ctx->b) - OUT(&result[8], ctx->c) - OUT(&result[12], ctx->d) + OUT(&result[0], ctx->a); + OUT(&result[4], ctx->b); + OUT(&result[8], ctx->c); + OUT(&result[12], ctx->d); memset(ctx, 0, sizeof(*ctx)); } From b6e0a2381c86389729e690899f8be2f797c29d34 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 09:39:15 +0200 Subject: [PATCH 10/15] [winpr,crypto] fix duplicate include --- winpr/libwinpr/crypto/hmac_md5.c | 1 - 1 file changed, 1 deletion(-) diff --git a/winpr/libwinpr/crypto/hmac_md5.c b/winpr/libwinpr/crypto/hmac_md5.c index 5550bbd06..100c212f1 100644 --- a/winpr/libwinpr/crypto/hmac_md5.c +++ b/winpr/libwinpr/crypto/hmac_md5.c @@ -3,7 +3,6 @@ #include "hmac_md5.h" #include "md5.h" -#include void hmac_md5_init(WINPR_HMAC_MD5_CTX* ctx, const unsigned char* key, size_t key_len) { From efffcee11907272e049cbb100464f8c63ef08a1b Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 09:39:29 +0200 Subject: [PATCH 11/15] [channels,rdpecam] fix casts --- channels/rdpecam/client/encoding.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/channels/rdpecam/client/encoding.c b/channels/rdpecam/client/encoding.c index 2ce263fe4..5292fc0cc 100644 --- a/channels/rdpecam/client/encoding.c +++ b/channels/rdpecam/client/encoding.c @@ -18,6 +18,7 @@ */ #include +#include #include "camera.h" @@ -160,7 +161,7 @@ static BOOL ecam_encoder_compress_h264(CameraDeviceStream* stream, const BYTE* s #if defined(WITH_INPUT_FORMAT_MJPG) if (inputFormat == CAM_MEDIA_FORMAT_MJPG) { - stream->avInputPkt->data = (BYTE*)srcData; + stream->avInputPkt->data = WINPR_CAST_CONST_PTR_AWAY(srcData, BYTE*); stream->avInputPkt->size = srcSize; if (avcodec_send_packet(stream->avContext, stream->avInputPkt) < 0) @@ -195,8 +196,8 @@ static BOOL ecam_encoder_compress_h264(CameraDeviceStream* stream, const BYTE* s return FALSE; } - if (av_image_fill_pointers(srcSlice, pixFormat, (int)size.height, (BYTE*)srcData, - srcLineSizes) < 0) + if (av_image_fill_pointers(srcSlice, pixFormat, (int)size.height, + WINPR_CAST_CONST_PTR_AWAY(srcData, BYTE*), srcLineSizes) < 0) { WLog_ERR(TAG, "av_image_fill_pointers failed"); return FALSE; From 4f4d400f7ecec50c8534b80133294f463ff467a6 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 09:41:08 +0200 Subject: [PATCH 12/15] [core,gateway] fix out of range check --- libfreerdp/core/gateway/websocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfreerdp/core/gateway/websocket.c b/libfreerdp/core/gateway/websocket.c index 2bfeff5f2..b2a2d6de8 100644 --- a/libfreerdp/core/gateway/websocket.c +++ b/libfreerdp/core/gateway/websocket.c @@ -156,7 +156,7 @@ int websocket_write(BIO* bio, const BYTE* buf, int isize, WEBSOCKET_OPCODE opcod winpr_RAND(&maskingKey, sizeof(maskingKey)); payloadSize = isize; - if ((isize < 0) || (isize > UINT32_MAX)) + if (isize < 0) return -1; if (payloadSize < 126) From 9e18bd94f934442afdc5978e9591ef570afcbcd2 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 09:46:39 +0200 Subject: [PATCH 13/15] [crypto,x509] replace sprintf --- libfreerdp/crypto/x509_utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreerdp/crypto/x509_utils.c b/libfreerdp/crypto/x509_utils.c index 60a3c07c3..3a5826640 100644 --- a/libfreerdp/crypto/x509_utils.c +++ b/libfreerdp/crypto/x509_utils.c @@ -129,8 +129,8 @@ static const char* general_name_type_label(int general_name_type) } else { - static char buffer[80]; - (void)sprintf(buffer, "Unknown general name type (%d)", general_name_type); + static char buffer[80] = { 0 }; + (void)snprintf(buffer, sizeof(buffer), "Unknown general name type (%d)", general_name_type); return buffer; } } From 28037f100cb60aa12f1f526e642463149ca9d22e Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 10:10:33 +0200 Subject: [PATCH 14/15] [warnings] fix sign comparison issues --- libfreerdp/primitives/sse/prim_copy_avx2.c | 2 +- libfreerdp/primitives/sse/prim_copy_sse4_1.c | 2 +- winpr/libwinpr/clipboard/synthetic.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libfreerdp/primitives/sse/prim_copy_avx2.c b/libfreerdp/primitives/sse/prim_copy_avx2.c index 644f6f61f..57af2d30c 100644 --- a/libfreerdp/primitives/sse/prim_copy_avx2.c +++ b/libfreerdp/primitives/sse/prim_copy_avx2.c @@ -62,7 +62,7 @@ static INLINE pstatus_t avx2_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstDa const SSIZE_T width = nWidth - rem; const size_t align = nSrcStep % 32; - const BOOL fast = (align == 0) ? TRUE : (align >= 8 - MIN(8, rem) ? TRUE : FALSE); + const BOOL fast = (align == 0) ? TRUE : (align >= 8 - MIN(8, (size_t)rem) ? TRUE : FALSE); for (SSIZE_T y = 0; y < nHeight; y++) { const BYTE* WINPR_RESTRICT srcLine = diff --git a/libfreerdp/primitives/sse/prim_copy_sse4_1.c b/libfreerdp/primitives/sse/prim_copy_sse4_1.c index 8419db00a..108123d2b 100644 --- a/libfreerdp/primitives/sse/prim_copy_sse4_1.c +++ b/libfreerdp/primitives/sse/prim_copy_sse4_1.c @@ -57,7 +57,7 @@ static INLINE pstatus_t sse_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstDat const SSIZE_T rem = nWidth % 4; const size_t align = nSrcStep % 64; - const BOOL fast = (align == 0) ? TRUE : (align >= 16 - MIN(16, rem) ? TRUE : FALSE); + const BOOL fast = (align == 0) ? TRUE : (align >= 16 - MIN(16, (size_t)rem) ? TRUE : FALSE); const SSIZE_T width = nWidth - rem; for (SSIZE_T y = 0; y < nHeight; y++) { diff --git a/winpr/libwinpr/clipboard/synthetic.c b/winpr/libwinpr/clipboard/synthetic.c index f1406bc26..4958493a1 100644 --- a/winpr/libwinpr/clipboard/synthetic.c +++ b/winpr/libwinpr/clipboard/synthetic.c @@ -602,8 +602,8 @@ static void* clipboard_synthesize_text_html(wClipboard* clipboard, UINT32 format const long end = strtol(&endStr[8], NULL, 10); - if (beg < 0 || end < 0 || (beg > SrcSize) || (end > SrcSize) || (beg >= end) || - (errno != 0)) + if (beg < 0 || end < 0 || ((size_t)beg > SrcSize) || ((size_t)end > SrcSize) || + (beg >= end) || (errno != 0)) return NULL; const size_t DstSize = (size_t)(end - beg); From 6ac2a961b6480c1d6f54b51f5e7ef269aaed4ce0 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Oct 2024 10:08:16 +0200 Subject: [PATCH 15/15] [channels,audin] fix variable shadowing --- channels/audin/client/alsa/audin_alsa.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/channels/audin/client/alsa/audin_alsa.c b/channels/audin/client/alsa/audin_alsa.c index f77aa7e1f..7b71990f2 100644 --- a/channels/audin/client/alsa/audin_alsa.c +++ b/channels/audin/client/alsa/audin_alsa.c @@ -174,9 +174,9 @@ static DWORD WINAPI audin_alsa_thread_func(LPVOID arg) if (framesRead == -EPIPE) { - const int rc = snd_pcm_recover(capture_handle, (int)framesRead, 0); - if (rc < 0) - WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_recover (%s)", snd_strerror(rc)); + const int res = snd_pcm_recover(capture_handle, (int)framesRead, 0); + if (res < 0) + WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_recover (%s)", snd_strerror(res)); continue; } @@ -202,9 +202,9 @@ static DWORD WINAPI audin_alsa_thread_func(LPVOID arg) if (capture_handle) { - const int rc = snd_pcm_close(capture_handle); - if (rc < 0) - WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_close (%s)", snd_strerror(rc)); + const int res = snd_pcm_close(capture_handle); + if (res < 0) + WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_close (%s)", snd_strerror(res)); } out: