Skip to content

Commit 37597b7

Browse files
committed
tests: fix static-analysis defects (clang-tidy, check-source-text)
- test_dh.c: zero-initialize priv/pub in test_wc_DhCheckKeyPair. clang-tidy flags pub[pubSz-1] ^= 0x01 as a read of an uninitialized variable (it cannot see that wc_DhGenerateKeyPair fills pub at runtime), failing all-c89-clang-tidy / clang-tidy-all-intelasm / clang-tidy-all-async-quic. - test_curve25519_whitebox.c: wrap the BAD_FUNC_ARG operands in WC_NO_ERR_TRACE() (check-source-text unescaped-error-code check). - test_sha3_whitebox.c: drop the bogus WOLFSSL_NO_SHA3 guard (no such macro; the real gate is WOLFSSL_SHA3), which check-source-text reported as an unknown macro.
1 parent 622befe commit 37597b7

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

tests/api/test_dh.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,10 @@ int test_wc_DhCheckKeyPair(void)
904904
!defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
905905
DhKey key;
906906
WC_RNG rng;
907-
byte priv[TEST_DH_BUF_SIZE], pub[TEST_DH_BUF_SIZE];
907+
/* zero-initialized: wc_DhGenerateKeyPair fills pub at runtime, but the
908+
* later read-modify-write (pub[pubSz-1] ^= 0x01) reads as uninitialized
909+
* to clang-tidy without this. */
910+
byte priv[TEST_DH_BUF_SIZE] = {0}, pub[TEST_DH_BUF_SIZE] = {0};
908911
word32 privSz = sizeof(priv), pubSz = sizeof(pub);
909912

910913
ExpectIntEQ(wc_InitRng(&rng), 0);

tests/unit-mcdc/test_curve25519_whitebox.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void wb_make_pub_nb(void)
7878

7979
/* key == NULL: TRUE side. */
8080
ret = wc_curve25519_make_pub_nb(NULL);
81-
if (ret != BAD_FUNC_ARG) {
81+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
8282
WB_NOTE("wc_curve25519_make_pub_nb(NULL) did not return "
8383
"BAD_FUNC_ARG");
8484
wb_fail = 1;
@@ -96,7 +96,7 @@ static void wb_make_pub_nb(void)
9696
XMEMSET(&key, 0, sizeof(key));
9797
key.nb_ctx = NULL;
9898
ret = wc_curve25519_make_pub_nb(&key);
99-
if (ret != BAD_FUNC_ARG) {
99+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
100100
WB_NOTE("wc_curve25519_make_pub_nb(nb_ctx==NULL) did not "
101101
"return BAD_FUNC_ARG");
102102
wb_fail = 1;
@@ -157,7 +157,7 @@ static void wb_make_key_nb(void)
157157
/* key == NULL: TRUE side (rng operand short-circuited, not evaluated
158158
* -- unique-cause MC/DC only requires this operand's own pair). */
159159
ret = wc_curve25519_make_key_nb(&rng, CURVE25519_KEYSIZE, NULL);
160-
if (ret != BAD_FUNC_ARG) {
160+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
161161
WB_NOTE("wc_curve25519_make_key_nb(NULL key) did not return "
162162
"BAD_FUNC_ARG");
163163
wb_fail = 1;
@@ -166,7 +166,7 @@ static void wb_make_key_nb(void)
166166
/* rng == NULL, key != NULL: second operand's TRUE side with the first
167167
* operand false. */
168168
ret = wc_curve25519_make_key_nb(NULL, CURVE25519_KEYSIZE, &key);
169-
if (ret != BAD_FUNC_ARG) {
169+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
170170
WB_NOTE("wc_curve25519_make_key_nb(NULL rng) did not return "
171171
"BAD_FUNC_ARG");
172172
wb_fail = 1;
@@ -176,7 +176,7 @@ static void wb_make_key_nb(void)
176176
* following "if (ret==0 && ...)" compound (first operand FALSE side). */
177177
key.nb_ctx = NULL;
178178
ret = wc_curve25519_make_key_nb(&rng, CURVE25519_KEYSIZE, &key);
179-
if (ret != BAD_FUNC_ARG) {
179+
if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
180180
WB_NOTE("wc_curve25519_make_key_nb(nb_ctx==NULL) did not return "
181181
"BAD_FUNC_ARG");
182182
wb_fail = 1;

tests/unit-mcdc/test_sha3_whitebox.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
static int wb_fail = 0;
6161
#define WB_NOTE(msg) do { printf(" [wb] %s\n", (msg)); } while (0)
6262

63-
#if !defined(WOLFSSL_NO_SHA3) && defined(WOLFSSL_SHA3) && \
63+
#if defined(WOLFSSL_SHA3) && \
6464
defined(USE_INTEL_SPEEDUP) && !defined(WC_C_DYNAMIC_FALLBACK)
6565

6666
/* Run InitSha3 once with cpuid_flags/sha3_block forced, without hashing. The
@@ -177,7 +177,7 @@ static void wb_sha3_dispatch(void)
177177
* real (non-INITIALIZER) value and vary sha3_block, without hashing, so no
178178
* asm block ever executes.
179179
*/
180-
#if !defined(WOLFSSL_NO_SHA3) && defined(WOLFSSL_SHA3) && \
180+
#if defined(WOLFSSL_SHA3) && \
181181
defined(__aarch64__) && defined(WOLFSSL_ARMASM) && \
182182
!defined(WC_C_DYNAMIC_FALLBACK)
183183

@@ -225,7 +225,7 @@ static void wb_sha3_dispatch_aarch64(void)
225225
int main(void)
226226
{
227227
printf("sha3.c white-box MC/DC supplement\n");
228-
#if defined(WOLFSSL_NO_SHA3) || !defined(WOLFSSL_SHA3)
228+
#if !defined(WOLFSSL_SHA3)
229229
printf(" SHA-3 not enabled; nothing to exercise\n");
230230
return 0;
231231
#else

0 commit comments

Comments
 (0)