wolfcrypt/src/wc_port.c and wolfssl/wolfcrypt/wc_port.h: add volatile attribute to wolfSSL_Atomic_Uint_CompareExchange() first arg, for pedantic accuracy;

wolfssl/internal.h and src/ssl.c: add volatile attribute to WOLFSSL_CTX.privateKeyPKey pointer, for pedantic accuracy;

wolfcrypt/test/test.c: in memory_test(), use compatible pointers for all operands in the wolfSSL_Atomic_Ptr_CompareExchange() test, to avoid undefined behavior.
This commit is contained in:
Daniel Pouzzner
2025-11-24 18:21:09 -06:00
parent 59f4fa5686
commit e459b21744
5 changed files with 26 additions and 20 deletions

View File

@@ -1359,7 +1359,7 @@ int wolfSSL_Atomic_Uint_CompareExchange(
}
int wolfSSL_Atomic_Ptr_CompareExchange(
void **c, void **expected_ptr, void *new_ptr)
void * volatile *c, void **expected_ptr, void *new_ptr)
{
uintptr_t exp = (uintptr_t)*expected_ptr;
int ret = atomic_fcmpset_ptr((uintptr_t *)c, &exp, (uintptr_t)new_ptr);
@@ -1456,7 +1456,7 @@ int wolfSSL_Atomic_Uint_CompareExchange(
}
int wolfSSL_Atomic_Ptr_CompareExchange(
void **c, void **expected_ptr, void *new_ptr)
void * volatile *c, void **expected_ptr, void *new_ptr)
{
/* use gcc-built-in __atomic_compare_exchange_n(), not
* atomic_compare_exchange_strong_explicit(), to sidestep _Atomic type
@@ -1551,7 +1551,7 @@ int wolfSSL_Atomic_Uint_CompareExchange(
}
int wolfSSL_Atomic_Ptr_CompareExchange(
void **c, void **expected_ptr, void *new_ptr)
void * volatile *c, void **expected_ptr, void *new_ptr)
{
return __atomic_compare_exchange_n(
c, expected_ptr, new_ptr, 0 /* weak */,
@@ -1651,7 +1651,7 @@ int wolfSSL_Atomic_Uint_CompareExchange(
}
int wolfSSL_Atomic_Ptr_CompareExchange(
void ** c, void **expected_ptr, void *new_ptr)
void * volatile * c, void **expected_ptr, void *new_ptr)
{
#ifdef _WIN64
LONG64 actual_ptr = InterlockedCompareExchange64(

View File

@@ -20061,8 +20061,6 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
#endif
int int_expected;
unsigned int uint_expected;
void * a_ptr = NULL;
void * ptr_expected = NULL;
if (WOLFSSL_ATOMIC_LOAD(a_int) != -2)
return WC_TEST_RET_ENC_NC;
@@ -20134,12 +20132,17 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
if (WOLFSSL_ATOMIC_LOAD(a_uint) != 7)
return WC_TEST_RET_ENC_NC;
a_ptr = NULL;
ptr_expected = NULL;
if (! wolfSSL_Atomic_Ptr_CompareExchange(&a_ptr, &ptr_expected, &ret))
return WC_TEST_RET_ENC_NC;
if (a_ptr != &ret)
return WC_TEST_RET_ENC_NC;
{
void * volatile a_ptr = NULL;
void * ptr_expected = NULL;
static const char s[] = "";
if (! wolfSSL_Atomic_Ptr_CompareExchange(&a_ptr,
&ptr_expected,
(void *)&s))
return WC_TEST_RET_ENC_NC;
if (a_ptr != s)
return WC_TEST_RET_ENC_NC;
}
}
return ret;