Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,14 @@ if (CLR_CMAKE_HOST_UNIX)
# Disable frame pointer optimizations so profilers can get better call stacks
add_compile_options(-fno-omit-frame-pointer)

# Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around
# Make signed overflow well-defined. Implies the following flags in clang-20 and above.
# -fwrapv - Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around
# using twos-complement representation (this is normally undefined according to the C++ spec).
add_compile_options(-fwrapv)
# -fwrapv-pointer - The same as -fwrapv but for pointers.
add_compile_options(-fno-strict-overflow)

# Suppress C++ strict aliasing rules. This matches our use of MSVC.
add_compile_options(-fno-strict-aliasing)

if(CLR_CMAKE_HOST_APPLE)
# Clang will by default emit objc_msgSend stubs in Xcode 14, which ld from earlier Xcodes doesn't understand.
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/debug/di/rspriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -6397,8 +6397,8 @@ class CordbThread : public CordbBase, public ICorDebugThread,
// Lazily initialized.
EXCEPTION_RECORD * m_pExceptionRecord;

static const CorDebugUserState kInvalidUserState = CorDebugUserState(-1);
CorDebugUserState m_userState; // This is the current state of the
static const int kInvalidUserState = -1;
int m_userState; // This is the current state of the
// thread, at the time that the
// left side synchronized

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/debug/di/rsthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ CorDebugUserState CordbThread::GetUserState()
m_userState = pDAC->GetUserState(m_vmThreadToken);
}

return m_userState;
return (CorDebugUserState)m_userState;
}


Expand Down Expand Up @@ -886,7 +886,7 @@ HRESULT CordbThread::CreateStepper(ICorDebugStepper ** ppStepper)
//Returns true if current user state of a thread is USER_WAIT_SLEEP_JOIN
bool CordbThread::IsThreadWaitingOrSleeping()
{
CorDebugUserState userState = m_userState;
int userState = m_userState;
if (userState == kInvalidUserState)
{
//If m_userState is not ready, we'll read from DAC only part of it which
Expand Down
4 changes: 2 additions & 2 deletions src/native/libs/System.Native/pal_interfaceaddresses.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ int32_t SystemNative_EnumerateGatewayAddressesForInterface(void* context, uint32
return -1;
}

uint8_t* buffer = malloc(byteCount);
uint8_t* buffer = (uint8_t*)malloc(byteCount);
if (buffer == NULL)
{
errno = ENOMEM;
Expand All @@ -587,7 +587,7 @@ int32_t SystemNative_EnumerateGatewayAddressesForInterface(void* context, uint32

byteCount = tmpEstimatedSize;
free(buffer);
buffer = malloc(byteCount);
buffer = (uint8_t*)malloc(byteCount);
if (buffer == NULL)
{
errno = ENOMEM;
Expand Down
8 changes: 5 additions & 3 deletions src/native/libs/System.Native/pal_networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ int32_t SystemNative_GetHostEntryForName(const uint8_t* address, int32_t address
char name[_POSIX_HOST_NAME_MAX];
result = gethostname((char*)name, _POSIX_HOST_NAME_MAX);

bool includeIPv4Loopback = true;
bool includeIPv6Loopback = true;
bool includeIPv4Loopback;
bool includeIPv6Loopback;
includeIPv4Loopback = true;
includeIPv6Loopback = true;

if (result == 0 && strcasecmp((const char*)address, name) == 0)
{
Expand Down Expand Up @@ -1526,7 +1528,7 @@ int32_t SystemNative_ReceiveSocketError(intptr_t socket, MessageHeader* messageH
#if HAVE_LINUX_ERRQUEUE_H
char buffer[sizeof(struct sock_extended_err) + sizeof(struct sockaddr_storage)];
messageHeader->ControlBufferLen = sizeof(buffer);
messageHeader->ControlBuffer = (void*)buffer;
messageHeader->ControlBuffer = (uint8_t*)buffer;

struct msghdr header;
struct icmphdr icmph;
Expand Down
2 changes: 1 addition & 1 deletion src/native/libs/System.Native/pal_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ int32_t SystemNative_ForkAndExecProcess(const char* filename,

if (setCredentials && groupsLength > 0)
{
getGroupsBuffer = malloc(sizeof(uint32_t) * Int32ToSizeT(groupsLength));
getGroupsBuffer = (uint32_t*)(malloc(sizeof(uint32_t) * Int32ToSizeT(groupsLength)));
if (getGroupsBuffer == NULL)
{
success = false;
Expand Down
2 changes: 1 addition & 1 deletion src/native/libs/System.Native/pal_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static bool TryConvertSignalCodeToPosixSignal(int signalCode, PosixSignal* posix
return true;

default:
*posixSignal = signalCode;
*posixSignal = (PosixSignal)signalCode;
return false;
}
}
Expand Down
23 changes: 11 additions & 12 deletions src/native/libs/System.Native/pal_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ LowLevelMonitor* SystemNative_LowLevelMonitor_Create(void)

error = pthread_cond_init(&monitor->Condition, &conditionAttributes);

int condAttrDestroyError = pthread_condattr_destroy(&conditionAttributes);
int condAttrDestroyError;
condAttrDestroyError = pthread_condattr_destroy(&conditionAttributes);
assert(condAttrDestroyError == 0);
(void)condAttrDestroyError; // unused in release build
#else
error = pthread_cond_init(&monitor->Condition, NULL);
#endif
Expand Down Expand Up @@ -117,18 +117,17 @@ void SystemNative_LowLevelMonitor_Destroy(LowLevelMonitor* monitor)
error = pthread_mutex_destroy(&monitor->Mutex);
assert(error == 0);

(void)error; // unused in release build

free(monitor);
}

void SystemNative_LowLevelMonitor_Acquire(LowLevelMonitor* monitor)
{
assert(monitor != NULL);

int error = pthread_mutex_lock(&monitor->Mutex);
int error;

error = pthread_mutex_lock(&monitor->Mutex);
assert(error == 0);
(void)error; // unused in release build

SetIsLocked(monitor, true);
}
Expand All @@ -139,9 +138,10 @@ void SystemNative_LowLevelMonitor_Release(LowLevelMonitor* monitor)

SetIsLocked(monitor, false);

int error = pthread_mutex_unlock(&monitor->Mutex);
int error;

error = pthread_mutex_unlock(&monitor->Mutex);
assert(error == 0);
(void)error; // unused in release build
}

void SystemNative_LowLevelMonitor_Wait(LowLevelMonitor* monitor)
Expand All @@ -150,9 +150,10 @@ void SystemNative_LowLevelMonitor_Wait(LowLevelMonitor* monitor)

SetIsLocked(monitor, false);

int error = pthread_cond_wait(&monitor->Condition, &monitor->Mutex);
int error;

error = pthread_cond_wait(&monitor->Condition, &monitor->Mutex);
assert(error == 0);
(void)error; // unused in release build

SetIsLocked(monitor, true);
}
Expand Down Expand Up @@ -212,8 +213,6 @@ void SystemNative_LowLevelMonitor_Signal_Release(LowLevelMonitor* monitor)

error = pthread_mutex_unlock(&monitor->Mutex);
assert(error == 0);

(void)error; // unused in release build
}

int32_t SystemNative_CreateThread(uintptr_t stackSize, void *(*startAddress)(void*), void *parameter)
Expand Down
2 changes: 1 addition & 1 deletion src/native/libs/System.Net.Security.Native/pal_gssapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ uint32_t NetSecurityNative_ImportPrincipalName(uint32_t* minorStatus,
// Principal name will usually be in the form SERVICE/HOST. But SPNEGO protocol prefers
// GSS_C_NT_HOSTBASED_SERVICE format. That format uses '@' separator instead of '/' between
// service name and host name. So convert input string into that format.
char* ptrSlash = memchr(inputName, '/', inputNameLen);
char* ptrSlash = (char*)memchr(inputName, '/', inputNameLen);
char* inputNameCopy = NULL;
if (ptrSlash != NULL)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static void do_track_entry(header_t* entry, int32_t add)

static void* mallocFunction(size_t size, const char *file, int line)
{
header_t* entry = malloc(size + sizeof(header_t));
header_t* entry = (header_t*)malloc(size + sizeof(header_t));
if (entry != NULL)
{
init_memory_entry(entry, size, file, line);
Expand All @@ -187,7 +187,7 @@ static void* reallocFunction (void *ptr, size_t size, const char *file, int line
}

void* toReturn = NULL;
header_t* newEntry = (header_t*) realloc((void*)entry, size + sizeof(header_t));
header_t* newEntry = (header_t*)realloc((void*)entry, size + sizeof(header_t));
if (newEntry != NULL)
{
entry = newEntry;
Expand Down Expand Up @@ -279,7 +279,7 @@ void CryptoNative_ForEachTrackedAllocation(void (*callback)(void* ptr, uint64_t

static void init_tracking_lists(void)
{
g_trackedMemory = malloc(kPartitionCount * sizeof(list_t));
g_trackedMemory = (list_t*)malloc(kPartitionCount * sizeof(list_t));
for (uint32_t i = 0; i < kPartitionCount; i++)
{
list_init(&g_trackedMemory[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ static int32_t EnsureOpenSsl10Initialized(void)
int numLocks = 0;
int locksInitialized = 0;
int randPollResult = 0;
size_t allocationSize = 0;

pthread_mutex_lock(&g_initLock);

Expand All @@ -1390,7 +1391,6 @@ static int32_t EnsureOpenSsl10Initialized(void)
}

// Create the locks array
size_t allocationSize = 0;
if (!multiply_s(sizeof(pthread_mutex_t), (size_t)numLocks, &allocationSize))
{
ret = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ extern TYPEOF(OPENSSL_gmtime)* OPENSSL_gmtime_ptr;
#define sk_X509_push(stack,value) OPENSSL_sk_push((OPENSSL_STACK*)(1 ? stack : (STACK_OF(X509)*)0), (const void*)(1 ? value : (X509*)0))

// type-safe OPENSSL_sk_pop
#define sk_X509_pop(stack) OPENSSL_sk_pop((OPENSSL_STACK*)(1 ? stack : (STACK_OF(X509)*)0))
#define sk_X509_pop(stack) ((X509*)OPENSSL_sk_pop((OPENSSL_STACK*)(1 ? stack : (STACK_OF(X509)*)0)))

// type-safe OPENSSL_sk_pop_free
#define sk_X509_pop_free(stack, freefunc) OPENSSL_sk_pop_free((OPENSSL_STACK*)(1 ? stack : (STACK_OF(X509)*)0), (OPENSSL_sk_freefunc)(1 ? freefunc : (sk_X509_freefunc)0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ int32_t CryptoNative_EvpPKeyGetEcCurveParameters(
EC_GROUP* group = NULL;
size_t generatorBufferSize = 0;
unsigned char* generatorBuffer = NULL;
int curveTypeNID;
int fieldTypeNID;

// Exit if CryptoNative_EvpPKeyGetEcKeyParameters failed
if (rc != 1)
Expand All @@ -798,7 +800,6 @@ int32_t CryptoNative_EvpPKeyGetEcCurveParameters(
if (!xBn || !yBn)
goto error;

int curveTypeNID;
if (!CryptoNative_EvpPKeyGetEcGroupNid(pkey, &curveTypeNID) || !curveTypeNID)
goto error;

Expand All @@ -819,7 +820,7 @@ int32_t CryptoNative_EvpPKeyGetEcCurveParameters(
// and some providers seem to be ignoring OSSL_PKEY_PARAM_EC_FIELD_TYPE.
// This is specifically true for tpm2 provider.
// We can reliably get the field type from the EC_GROUP.
int fieldTypeNID = EC_GROUP_get_field_type(group);
fieldTypeNID = EC_GROUP_get_field_type(group);

*curveType = NIDToCurveType(fieldTypeNID);
if (*curveType == Unspecified)
Expand Down
90 changes: 47 additions & 43 deletions src/native/libs/System.Security.Cryptography.Native/pal_evp_kdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,26 @@ int32_t CryptoNative_KbkdfHmacOneShot(
goto cleanup;
}

size_t keyLengthT = Int32ToSizeT(keyLength);
size_t destinationLengthT = Int32ToSizeT(destinationLength);
size_t labelLengthT = Int32ToSizeT(labelLength);
size_t contextLengthT = Int32ToSizeT(contextLength);

OSSL_PARAM params[] =
{
OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, algorithm, 0),
OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC, "HMAC", 0),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (void*)key, keyLengthT),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (void*)label, labelLengthT),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (void*)context, contextLengthT),
OSSL_PARAM_construct_end(),
};

if (EVP_KDF_derive(ctx, destination, destinationLengthT, params) <= 0)
{
goto cleanup;
size_t keyLengthT = Int32ToSizeT(keyLength);
size_t destinationLengthT = Int32ToSizeT(destinationLength);
size_t labelLengthT = Int32ToSizeT(labelLength);
size_t contextLengthT = Int32ToSizeT(contextLength);

OSSL_PARAM params[] =
{
OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, algorithm, 0),
OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC, "HMAC", 0),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (void*)key, keyLengthT),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (void*)label, labelLengthT),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (void*)context, contextLengthT),
OSSL_PARAM_construct_end(),
};

if (EVP_KDF_derive(ctx, destination, destinationLengthT, params) <= 0)
{
goto cleanup;
}
}

ret = 1;
Expand Down Expand Up @@ -199,33 +201,35 @@ static int32_t HkdfCore(
goto cleanup;
}

size_t keyLengthT = Int32ToSizeT(keyLength);
size_t destinationLengthT = Int32ToSizeT(destinationLength);

OSSL_PARAM params[6] = {{0}};
int i = 0;
params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (void*)key, keyLengthT);
params[i++] = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, algorithm, 0);

if (salt != NULL && saltLength > 0)
{
size_t saltLengthT = Int32ToSizeT(saltLength);
params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (void*)salt, saltLengthT);
}

if (info != NULL && infoLength > 0)
{
size_t infoLengthT = Int32ToSizeT(infoLength);
params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (void*)info, infoLengthT);
}

params[i++] = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &operation);
params[i] = OSSL_PARAM_construct_end();
assert(i < 6);

if (EVP_KDF_derive(ctx, destination, destinationLengthT, params) <= 0)
{
goto cleanup;
size_t keyLengthT = Int32ToSizeT(keyLength);
size_t destinationLengthT = Int32ToSizeT(destinationLength);

OSSL_PARAM params[6] = {{0}};
int i = 0;
params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (void*)key, keyLengthT);
params[i++] = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, algorithm, 0);

if (salt != NULL && saltLength > 0)
{
size_t saltLengthT = Int32ToSizeT(saltLength);
params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (void*)salt, saltLengthT);
}

if (info != NULL && infoLength > 0)
{
size_t infoLengthT = Int32ToSizeT(infoLength);
params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (void*)info, infoLengthT);
}

params[i++] = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &operation);
params[i] = OSSL_PARAM_construct_end();
assert(i < 6);

if (EVP_KDF_derive(ctx, destination, destinationLengthT, params) <= 0)
{
goto cleanup;
}
}

ret = 1;
Expand Down
Loading
Loading