diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c index 7ebe85285..36eaf78e5 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm.c @@ -169,8 +169,8 @@ static int ntlm_SetContextServicePrincipalNameW(NTLM_CONTEXT* context, LPWSTR Se if (!context->ServicePrincipalName.Buffer) return -1; - CopyMemory(context->ServicePrincipalName.Buffer, ServicePrincipalName, - context->ServicePrincipalName.Length + 2); + memcpy(context->ServicePrincipalName.Buffer, ServicePrincipalName, + context->ServicePrincipalName.Length + 2); return 1; } diff --git a/winpr/libwinpr/utils/ntlm.c b/winpr/libwinpr/utils/ntlm.c index f682f0555..6c6083b44 100644 --- a/winpr/libwinpr/utils/ntlm.c +++ b/winpr/libwinpr/utils/ntlm.c @@ -56,7 +56,7 @@ BOOL NTOWFv1A(LPSTR Password, UINT32 PasswordLength, BYTE* NtHash) if (!PasswordW) return FALSE; - if (!NTOWFv1W(PasswordW, pwdCharLength * sizeof(WCHAR), NtHash)) + if (!NTOWFv1W(PasswordW, (UINT32)pwdCharLength * sizeof(WCHAR), NtHash)) goto out_fail; result = TRUE; @@ -107,8 +107,9 @@ BOOL NTOWFv2A(LPSTR Password, UINT32 PasswordLength, LPSTR User, UINT32 UserLeng if (!UserW || !DomainW || !PasswordW) goto out_fail; - if (!NTOWFv2W(PasswordW, pwdCharLength * sizeof(WCHAR), UserW, userCharLength * sizeof(WCHAR), - DomainW, domainCharLength * sizeof(WCHAR), NtHash)) + if (!NTOWFv2W(PasswordW, (UINT32)pwdCharLength * sizeof(WCHAR), UserW, + (UINT32)userCharLength * sizeof(WCHAR), DomainW, + (UINT32)domainCharLength * sizeof(WCHAR), NtHash)) goto out_fail; result = TRUE; @@ -169,8 +170,8 @@ BOOL NTOWFv2FromHashA(BYTE* NtHashV1, LPSTR User, UINT32 UserLength, LPSTR Domai if (!UserW || !DomainW) goto out_fail; - if (!NTOWFv2FromHashW(NtHashV1, UserW, userCharLength * sizeof(WCHAR), DomainW, - domainCharLength * sizeof(WCHAR), NtHash)) + if (!NTOWFv2FromHashW(NtHashV1, UserW, (UINT32)userCharLength * sizeof(WCHAR), DomainW, + (UINT32)domainCharLength * sizeof(WCHAR), NtHash)) goto out_fail; result = TRUE; diff --git a/winpr/libwinpr/utils/sam.c b/winpr/libwinpr/utils/sam.c index 6eed78aec..6ca544d49 100644 --- a/winpr/libwinpr/utils/sam.c +++ b/winpr/libwinpr/utils/sam.c @@ -348,7 +348,7 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPCWSTR User, UINT32 UserLength, if (!utfDomain) goto fail; } - entry = SamLookupUserA(sam, utfUser, userCharLen, utfDomain, domainCharLen); + entry = SamLookupUserA(sam, utfUser, (UINT32)userCharLen, utfDomain, (UINT32)domainCharLen); fail: free(utfUser); free(utfDomain); diff --git a/winpr/libwinpr/utils/windows/debug.c b/winpr/libwinpr/utils/windows/debug.c index 41545c75b..3577fbf3a 100644 --- a/winpr/libwinpr/utils/windows/debug.c +++ b/winpr/libwinpr/utils/windows/debug.c @@ -141,8 +141,8 @@ char* winpr_win_strerror(DWORD dw, char* dmsg, size_t size) alloc = TRUE; dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; #else - nSize = (DWORD)(size * 2); - msg = (LPTSTR)calloc(nSize, sizeof(TCHAR)); + nSize = (DWORD)(size * sizeof(WCHAR)); + msg = (LPTSTR)calloc(nSize, sizeof(WCHAR)); #endif rc = FormatMessage(dwFlags, NULL, dw, 0, alloc ? (LPTSTR)&msg : msg, nSize, NULL); diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.c b/winpr/libwinpr/utils/wlog/PacketMessage.c index a07e76132..3d5da5894 100644 --- a/winpr/libwinpr/utils/wlog/PacketMessage.c +++ b/winpr/libwinpr/utils/wlog/PacketMessage.c @@ -469,8 +469,10 @@ BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, size_t length, DWORD flag tcp.UrgentPointer = 0; record.data = data; record.length = length; - record.header.incl_len = record.length + 14 + 20 + 20; - record.header.orig_len = record.length + 14 + 20 + 20; + const size_t offset = 14 + 20 + 20; + WINPR_ASSERT(record.length <= UINT32_MAX - offset); + record.header.incl_len = (UINT32)record.length + offset; + record.header.orig_len = (UINT32)record.length + offset; record.next = NULL; gettimeofday(&tp, 0); record.header.ts_sec = tp.tv_sec; diff --git a/winpr/tools/makecert/makecert.c b/winpr/tools/makecert/makecert.c index 5af503ba4..4e4fca9c1 100644 --- a/winpr/tools/makecert/makecert.c +++ b/winpr/tools/makecert/makecert.c @@ -735,7 +735,8 @@ static BOOL makecert_create_rsa(EVP_PKEY** ppkey, size_t key_length) if (EVP_PKEY_keygen_init(pctx) != 1) goto fail; - unsigned int keylen = key_length; + WINPR_ASSERT(key_length <= UINT_MAX); + unsigned int keylen = (unsigned int)key_length; const OSSL_PARAM params[] = { OSSL_PARAM_construct_uint("bits", &keylen), OSSL_PARAM_construct_end() }; if (EVP_PKEY_CTX_set_params(pctx, params) != 1)