diff --git a/include/freerdp/utils/aad.h b/include/freerdp/utils/aad.h index f7a7f163d..290393c65 100644 --- a/include/freerdp/utils/aad.h +++ b/include/freerdp/utils/aad.h @@ -134,8 +134,9 @@ extern "C" /** Helper to fetch a \b WINPR_JSON object from AAD/ARM::wellknown JSON * - * @param context The rdpContext to query for - * @param which The raw string name of the field to query + * @param log A logger instance to use + * @param base the base URL to connect to + * @param tenantid the tenant to use for the connection, use \b common for default * @return A \b WINPR_JSON object to be used for queries or \b NULL in case it does not exist. * * @since version 3.10.0 diff --git a/libfreerdp/common/assistance.c b/libfreerdp/common/assistance.c index 04d3ab008..ab0e6436e 100644 --- a/libfreerdp/common/assistance.c +++ b/libfreerdp/common/assistance.c @@ -876,7 +876,8 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas if (!pbIn || !pbOut) goto fail; - winpr_Data_Write_UINT32(pbIn, cbPassStubW); + WINPR_ASSERT(cbPasswordW <= UINT32_MAX); + winpr_Data_Write_UINT32(pbIn, (UINT32)cbPassStubW); CopyMemory(&pbIn[4], PassStubW, cbPassStubW); rc4Ctx = winpr_RC4_New(PasswordHash, sizeof(PasswordHash)); diff --git a/winpr/include/winpr/endian.h b/winpr/include/winpr/endian.h index 5d2104d4b..b3a5eeedf 100644 --- a/winpr/include/winpr/endian.h +++ b/winpr/include/winpr/endian.h @@ -27,6 +27,12 @@ #include #include +#ifdef __cplusplus +#define WINPR_ENDIAN_CAST(t, val) static_cast(val) +#else +#define WINPR_ENDIAN_CAST(t, val) (t)(val) +#endif + #ifdef __cplusplus extern "C" { @@ -35,195 +41,226 @@ extern "C" static INLINE UINT8 winpr_Data_Get_UINT8(const void* d) { WINPR_ASSERT(d); - return *(const UINT8*)d; + const UINT8* ptr = WINPR_ENDIAN_CAST(const UINT8*, d); + return *ptr; } static INLINE INT8 winpr_Data_Get_INT8(const void* d) { WINPR_ASSERT(d); - return *(const INT8*)d; + const INT8* ptr = WINPR_ENDIAN_CAST(const INT8*, d); + return *ptr; } static INLINE UINT16 winpr_Data_Get_UINT16_NE(const void* d) { - return *(const UINT16*)d; + const UINT16* ptr = WINPR_ENDIAN_CAST(const UINT16*, d); + return *ptr; } static INLINE UINT16 winpr_Data_Get_UINT16(const void* d) { + WINPR_ASSERT(d); + const UINT8* ptr = WINPR_ENDIAN_CAST(const UINT8*, d); const size_t typesize = sizeof(UINT16); UINT16 v = 0; for (size_t x = 0; x < typesize; x++) { v <<= 8; - v |= ((const UINT8*)d)[typesize - x - 1]; + v |= ptr[typesize - x - 1]; } return v; } static INLINE UINT16 winpr_Data_Get_UINT16_BE(const void* d) { + WINPR_ASSERT(d); + const UINT8* ptr = WINPR_ENDIAN_CAST(const UINT8*, d); const size_t typesize = sizeof(UINT16); UINT16 v = 0; for (size_t x = 0; x < typesize; x++) { v <<= 8; - v |= ((const UINT8*)d)[x]; + v |= ptr[x]; } return v; } static INLINE INT16 winpr_Data_Get_INT16_NE(const void* d) { - return *(const INT16*)d; + WINPR_ASSERT(d); + const INT16* ptr = WINPR_ENDIAN_CAST(const INT16*, d); + return *ptr; } static INLINE INT16 winpr_Data_Get_INT16(const void* d) { const UINT16 u16 = winpr_Data_Get_UINT16(d); - return (INT16)u16; + return WINPR_ENDIAN_CAST(INT16, u16); } static INLINE INT16 winpr_Data_Get_INT16_BE(const void* d) { const UINT16 u16 = winpr_Data_Get_UINT16_BE(d); - return (INT16)u16; + return WINPR_ENDIAN_CAST(INT16, u16); } static INLINE UINT32 winpr_Data_Get_UINT32_NE(const void* d) { - return *(const UINT32*)d; + WINPR_ASSERT(d); + const UINT32* ptr = WINPR_ENDIAN_CAST(const UINT32*, d); + return *ptr; } static INLINE UINT32 winpr_Data_Get_UINT32(const void* d) { + WINPR_ASSERT(d); + const UINT8* ptr = WINPR_ENDIAN_CAST(const UINT8*, d); const size_t typesize = sizeof(UINT32); UINT32 v = 0; for (size_t x = 0; x < typesize; x++) { v <<= 8; - v |= ((const UINT8*)d)[typesize - x - 1]; + v |= ptr[typesize - x - 1]; } return v; } static INLINE UINT32 winpr_Data_Get_UINT32_BE(const void* d) { + WINPR_ASSERT(d); + const UINT8* ptr = WINPR_ENDIAN_CAST(const UINT8*, d); const size_t typesize = sizeof(UINT32); UINT32 v = 0; for (size_t x = 0; x < typesize; x++) { v <<= 8; - v |= ((const UINT8*)d)[x]; + v |= ptr[x]; } return v; } static INLINE INT32 winpr_Data_Get_INT32_NE(const void* d) { - return *(const INT32*)d; + WINPR_ASSERT(d); + const INT32* ptr = WINPR_ENDIAN_CAST(const INT32*, d); + return *ptr; } static INLINE INT32 winpr_Data_Get_INT32(const void* d) { const UINT32 u32 = winpr_Data_Get_UINT32(d); - return (INT32)u32; + return WINPR_ENDIAN_CAST(INT32, u32); } static INLINE INT32 winpr_Data_Get_INT32_BE(const void* d) { const UINT32 u32 = winpr_Data_Get_UINT32_BE(d); - return (INT32)u32; + return WINPR_ENDIAN_CAST(INT32, u32); } static INLINE UINT64 winpr_Data_Get_UINT64_NE(const void* d) { - return *(const UINT64*)d; + WINPR_ASSERT(d); + const UINT64* ptr = WINPR_ENDIAN_CAST(const UINT64*, d); + return *ptr; } static INLINE UINT64 winpr_Data_Get_UINT64(const void* d) { + WINPR_ASSERT(d); + const UINT8* ptr = WINPR_ENDIAN_CAST(const UINT8*, d); const size_t typesize = sizeof(UINT64); UINT64 v = 0; for (size_t x = 0; x < typesize; x++) { v <<= 8; - v |= ((const UINT8*)d)[typesize - x - 1]; + v |= ptr[typesize - x - 1]; } return v; } static INLINE UINT64 winpr_Data_Get_UINT64_BE(const void* d) { + WINPR_ASSERT(d); + const UINT8* ptr = WINPR_ENDIAN_CAST(const UINT8*, d); const size_t typesize = sizeof(UINT64); UINT64 v = 0; for (size_t x = 0; x < typesize; x++) { v <<= 8; - v |= ((const UINT8*)d)[x]; + v |= ptr[x]; } return v; } static INLINE INT64 winpr_Data_Get_INT64_NE(const void* d) { - return *(const INT64*)d; + WINPR_ASSERT(d); + const INT64* b = WINPR_ENDIAN_CAST(const INT64*, d); + return *b; } static INLINE INT64 winpr_Data_Get_INT64(const void* d) { const UINT64 u64 = winpr_Data_Get_UINT64(d); - return (INT64)u64; + return WINPR_ENDIAN_CAST(INT64, u64); } static INLINE INT64 winpr_Data_Get_INT64_BE(const void* d) { const UINT64 u64 = winpr_Data_Get_UINT64_BE(d); - return (INT64)u64; + return WINPR_ENDIAN_CAST(INT64, u64); } static INLINE void winpr_Data_Write_UINT8_NE(void* d, UINT8 v) { WINPR_ASSERT(d); - *((UINT8*)d) = v; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); + *b = v; } static INLINE void winpr_Data_Write_UINT8(void* d, UINT8 v) { WINPR_ASSERT(d); - *((UINT8*)d) = v; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); + *b = v; } static INLINE void winpr_Data_Write_UINT16_NE(void* d, UINT16 v) { WINPR_ASSERT(d); - *((UINT16*)d) = v; + UINT16* b = WINPR_ENDIAN_CAST(UINT16*, d); + *b = v; } static INLINE void winpr_Data_Write_UINT16(void* d, UINT16 v) { WINPR_ASSERT(d); - ((UINT8*)d)[0] = v & 0xFF; - ((UINT8*)d)[1] = (v >> 8) & 0xFF; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); + b[0] = v & 0xFF; + b[1] = (v >> 8) & 0xFF; } static INLINE void winpr_Data_Write_UINT16_BE(void* d, UINT16 v) { WINPR_ASSERT(d); - ((UINT8*)d)[1] = v & 0xFF; - ((UINT8*)d)[0] = (v >> 8) & 0xFF; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); + b[1] = v & 0xFF; + b[0] = (v >> 8) & 0xFF; } static INLINE void winpr_Data_Write_UINT32_NE(void* d, UINT32 v) { WINPR_ASSERT(d); - *((UINT32*)d) = v; + UINT32* b = WINPR_ENDIAN_CAST(UINT32*, d); + *b = v; } static INLINE void winpr_Data_Write_UINT32(void* d, UINT32 v) { WINPR_ASSERT(d); - BYTE* b = (BYTE*)d; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); winpr_Data_Write_UINT16(b, v & 0xFFFF); winpr_Data_Write_UINT16(b + 2, (v >> 16) & 0xFFFF); } @@ -231,7 +268,7 @@ extern "C" static INLINE void winpr_Data_Write_UINT32_BE(void* d, UINT32 v) { WINPR_ASSERT(d); - BYTE* b = (BYTE*)d; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); winpr_Data_Write_UINT16_BE(b, (v >> 16) & 0xFFFF); winpr_Data_Write_UINT16_BE(b + 2, v & 0xFFFF); } @@ -239,13 +276,14 @@ extern "C" static INLINE void winpr_Data_Write_UINT64_NE(void* d, UINT64 v) { WINPR_ASSERT(d); - *((UINT64*)d) = v; + UINT64* b = WINPR_ENDIAN_CAST(UINT64*, d); + *b = v; } static INLINE void winpr_Data_Write_UINT64(void* d, UINT64 v) { WINPR_ASSERT(d); - BYTE* b = (BYTE*)d; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); winpr_Data_Write_UINT32(b, v & 0xFFFFFFFF); winpr_Data_Write_UINT32(b + 4, (v >> 32) & 0xFFFFFFFF); } @@ -253,7 +291,7 @@ extern "C" static INLINE void winpr_Data_Write_UINT64_BE(void* d, UINT64 v) { WINPR_ASSERT(d); - BYTE* b = (BYTE*)d; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); winpr_Data_Write_UINT32_BE(b, (v >> 32) & 0xFFFFFFFF); winpr_Data_Write_UINT32_BE(b + 4, v & 0xFFFFFFFF); } @@ -261,45 +299,51 @@ extern "C" static INLINE void winpr_Data_Write_INT8_NE(void* d, INT8 v) { WINPR_ASSERT(d); - *((INT8*)d) = v; + INT8* b = WINPR_ENDIAN_CAST(INT8*, d); + *b = v; } static INLINE void winpr_Data_Write_INT8(void* d, INT8 v) { WINPR_ASSERT(d); - *((INT8*)d) = v; + INT8* b = WINPR_ENDIAN_CAST(INT8*, d); + *b = v; } static INLINE void winpr_Data_Write_INT16_NE(void* d, INT16 v) { WINPR_ASSERT(d); - *((INT16*)d) = v; + INT16* b = WINPR_ENDIAN_CAST(INT16*, d); + *b = v; } static INLINE void winpr_Data_Write_INT16(void* d, INT16 v) { WINPR_ASSERT(d); - ((UINT8*)d)[0] = v & 0xFF; - ((UINT8*)d)[1] = (v >> 8) & 0xFF; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); + b[0] = v & 0xFF; + b[1] = (v >> 8) & 0xFF; } static INLINE void winpr_Data_Write_INT16_BE(void* d, INT16 v) { WINPR_ASSERT(d); - ((UINT8*)d)[1] = v & 0xFF; - ((UINT8*)d)[0] = (v >> 8) & 0xFF; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); + b[1] = v & 0xFF; + b[0] = (v >> 8) & 0xFF; } static INLINE void winpr_Data_Write_INT32_NE(void* d, INT32 v) { WINPR_ASSERT(d); - *((UINT32*)d) = v; + INT32* pu = WINPR_ENDIAN_CAST(INT32*, d); + *pu = v; } static INLINE void winpr_Data_Write_INT32(void* d, INT32 v) { WINPR_ASSERT(d); - BYTE* b = (BYTE*)d; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); winpr_Data_Write_UINT16(b, v & 0xFFFF); winpr_Data_Write_UINT16(b + 2, (v >> 16) & 0xFFFF); } @@ -307,7 +351,7 @@ extern "C" static INLINE void winpr_Data_Write_INT32_BE(void* d, INT32 v) { WINPR_ASSERT(d); - BYTE* b = (BYTE*)d; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); winpr_Data_Write_UINT16_BE(b, (v >> 16) & 0xFFFF); winpr_Data_Write_UINT16_BE(b + 2, v & 0xFFFF); } @@ -315,13 +359,14 @@ extern "C" static INLINE void winpr_Data_Write_INT64_NE(void* d, INT64 v) { WINPR_ASSERT(d); - *((UINT64*)d) = v; + INT64* pu = WINPR_ENDIAN_CAST(INT64*, d); + *pu = v; } static INLINE void winpr_Data_Write_INT64(void* d, INT64 v) { WINPR_ASSERT(d); - BYTE* b = (BYTE*)d; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); winpr_Data_Write_UINT32(b, v & 0xFFFFFFFF); winpr_Data_Write_UINT32(b + 4, (v >> 32) & 0xFFFFFFFF); } @@ -329,7 +374,7 @@ extern "C" static INLINE void winpr_Data_Write_INT64_BE(void* d, INT64 v) { WINPR_ASSERT(d); - BYTE* b = (BYTE*)d; + BYTE* b = WINPR_ENDIAN_CAST(BYTE*, d); winpr_Data_Write_UINT32_BE(b, (v >> 32) & 0xFFFFFFFF); winpr_Data_Write_UINT32_BE(b + 4, v & 0xFFFFFFFF); } diff --git a/winpr/libwinpr/utils/collections/StreamPool.c b/winpr/libwinpr/utils/collections/StreamPool.c index 0f7a52cf2..b550c9bad 100644 --- a/winpr/libwinpr/utils/collections/StreamPool.c +++ b/winpr/libwinpr/utils/collections/StreamPool.c @@ -451,14 +451,14 @@ char* StreamPool_GetStatistics(wStreamPool* pool, char* buffer, size_t size) "aSize =%" PRIuz ", uSize =%" PRIuz ", aCapacity=%" PRIuz ", uCapacity=%" PRIuz, pool->aSize, pool->uSize, pool->aCapacity, pool->uCapacity); - if ((offset > 0) && (offset < size)) + if ((offset > 0) && ((size_t)offset < size)) used += (size_t)offset; #if defined(WITH_STREAMPOOL_DEBUG) StreamPool_Lock(pool); offset = _snprintf(&buffer[used], size - 1 - used, "\n-- dump used array take locations --\n"); - if ((offset > 0) && (offset < size - used)) + if ((offset > 0) && ((size_t)offset < size - used)) used += (size_t)offset; for (size_t x = 0; x < pool->uSize; x++) { @@ -469,13 +469,13 @@ char* StreamPool_GetStatistics(wStreamPool* pool, char* buffer, size_t size) { offset = _snprintf(&buffer[used], size - 1 - used, "[%" PRIuz " | %" PRIuz "]: %s\n", x, y, cur->msg[y]); - if ((offset > 0) && (offset < size - used)) + if ((offset > 0) && ((size_t)offset < size - used)) used += (size_t)offset; } } offset = _snprintf(&buffer[used], size - 1 - used, "\n-- statistics called from --\n"); - if ((offset > 0) && (offset < size - used)) + if ((offset > 0) && ((size_t)offset < size - used)) used += (size_t)offset; struct s_StreamPoolEntry entry = { 0 }; @@ -488,7 +488,7 @@ char* StreamPool_GetStatistics(wStreamPool* pool, char* buffer, size_t size) { const char* msg = entry.msg[x]; offset = _snprintf(&buffer[used], size - 1 - used, "[%" PRIuz "]: %s\n", x, msg); - if ((offset > 0) && (offset < size - used)) + if ((offset > 0) && ((size_t)offset < size - used)) used += (size_t)offset; } free((void*)entry.msg); diff --git a/winpr/libwinpr/utils/unwind/debug.c b/winpr/libwinpr/utils/unwind/debug.c index 476f3ca93..585f21d7c 100644 --- a/winpr/libwinpr/utils/unwind/debug.c +++ b/winpr/libwinpr/utils/unwind/debug.c @@ -197,5 +197,6 @@ char** winpr_unwind_backtrace_symbols(void* buffer, size_t* used) dlinfo.dli_fname, dlinfo.dli_fbase, dlinfo.dli_sname, dlinfo.dli_saddr); } + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): function is an allocator return cnv.cpp; }