Merge pull request #10763 from akallabeth/fix-our-mistakes

Fix some mistakes
This commit is contained in:
akallabeth 2024-10-22 10:48:54 +02:00 committed by GitHub
commit 5ad826a503
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 151 additions and 138 deletions

View File

@ -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

View File

@ -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:

View File

@ -18,6 +18,7 @@
*/
#include <winpr/assert.h>
#include <winpr/winpr.h>
#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;

View File

@ -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")

View File

@ -25,7 +25,6 @@
#include <string.h>
#include <stdint.h>
#include <winpr/assert.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/assert.h>

View File

@ -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)

View File

@ -28,6 +28,7 @@
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/winpr.h>
#include <winpr/string.h>
#include <winpr/sspi.h>
#include <winpr/ssl.h>
@ -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);

View File

@ -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;
}
}

View File

@ -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 =

View File

@ -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++)
{

View File

@ -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);

View File

@ -3,7 +3,6 @@
#include "hmac_md5.h"
#include "md5.h"
#include <string.h>
void hmac_md5_init(WINPR_HMAC_MD5_CTX* ctx, const unsigned char* key, size_t key_len)
{

View File

@ -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));
}

View File

@ -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));
}

View File

@ -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

View File

@ -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,

View File

@ -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);