Skip to content

Commit 42c241d

Browse files
author
Andras Fekete
committed
Avoid use of uninitialized array
1 parent 2877b7b commit 42c241d

6 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/tls13.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4723,10 +4723,14 @@ static int EchCheckAcceptance(WOLFSSL* ssl, const byte* input,
47234723
int digestSize;
47244724
HS_Hashes* tmpHashes;
47254725
HS_Hashes* acceptHashes;
4726-
byte zeros[WC_MAX_DIGEST_SIZE] = {0};
4726+
byte zeros[WC_MAX_DIGEST_SIZE];
47274727
byte transcriptEchConf[WC_MAX_DIGEST_SIZE];
47284728
byte expandLabelPrk[WC_MAX_DIGEST_SIZE];
47294729
byte acceptConfirmation[ECH_ACCEPT_CONFIRMATION_SZ];
4730+
XMEMSET(zeros, 0, sizeof(zeros));
4731+
XMEMSET(transcriptEchConf, 0, sizeof(transcriptEchConf));
4732+
XMEMSET(expandLabelPrk, 0, sizeof(expandLabelPrk));
4733+
XMEMSET(acceptConfirmation, 0, sizeof(acceptConfirmation));
47304734
/* copy ech hashes to accept */
47314735
ret = InitHandshakeHashesAndCopy(ssl, ssl->hsHashesEch, &acceptHashes);
47324736
/* swap hsHashes to acceptHashes */
@@ -4839,9 +4843,12 @@ static int EchWriteAcceptance(WOLFSSL* ssl, byte* output,
48394843
int digestSize;
48404844
HS_Hashes* tmpHashes;
48414845
HS_Hashes* acceptHashes;
4842-
byte zeros[WC_MAX_DIGEST_SIZE] = {0};
4846+
byte zeros[WC_MAX_DIGEST_SIZE];
48434847
byte transcriptEchConf[WC_MAX_DIGEST_SIZE];
48444848
byte expandLabelPrk[WC_MAX_DIGEST_SIZE];
4849+
XMEMSET(zeros, 0, sizeof(zeros));
4850+
XMEMSET(transcriptEchConf, 0, sizeof(transcriptEchConf));
4851+
XMEMSET(expandLabelPrk, 0, sizeof(expandLabelPrk));
48454852

48464853
/* copy ech hashes to accept */
48474854
ret = InitHandshakeHashesAndCopy(ssl, ssl->hsHashes, &acceptHashes);
@@ -5710,7 +5717,7 @@ static void RefineSuites(WOLFSSL* ssl, Suites* peerSuites)
57105717
if (AllocateSuites(ssl) != 0)
57115718
return;
57125719

5713-
XMEMSET(suites, 0, WOLFSSL_MAX_SUITE_SZ);
5720+
XMEMSET(suites, 0, sizeof(suites));
57145721

57155722
if (!ssl->options.useClientOrder) {
57165723
/* Server order refining. */

tests/api.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16876,6 +16876,7 @@ static int test_wc_Chacha_SetKey(void)
1687616876
word32 keySz = (word32)(sizeof(key)/sizeof(byte));
1687716877
byte cipher[128];
1687816878

16879+
XMEMSET(cipher, 0, sizeof(cipher));
1687916880
ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, keySz), 0);
1688016881
/* Test bad args. */
1688116882
ExpectIntEQ(wc_Chacha_SetKey(NULL, key, keySz), BAD_FUNC_ARG);
@@ -54043,6 +54044,8 @@ static int test_wolfssl_EVP_chacha20(void)
5404354044
EVP_CIPHER_CTX* ctx = NULL;
5404454045
int outSz;
5404554046

54047+
XMEMSET(key, 0, sizeof(key));
54048+
XMEMSET(iv, 0, sizeof(iv));
5404654049
/* Encrypt. */
5404754050
ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
5404854051
ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,

tests/srp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ static void test_SrpSetPassword(void)
208208
byte v[64];
209209
word32 vSz = 0;
210210

211+
XMEMSET(v, 0, sizeof(v));
211212
AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
212213
AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
213214

@@ -262,6 +263,7 @@ static void test_SrpGetPublic(void)
262263
byte pub[64];
263264
word32 pubSz = 0;
264265

266+
XMEMSET(pub, 0, sizeof(pub));
265267
AssertIntEQ(0, wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
266268
AssertIntEQ(0, wc_SrpSetUsername(&srp, username, usernameSz));
267269
AssertIntEQ(0, wc_SrpSetParams(&srp, srp_N, sizeof(srp_N),
@@ -318,6 +320,8 @@ static void test_SrpComputeKey(void)
318320
word32 clientPubKeySz = 64;
319321
word32 serverPubKeySz = 64;
320322

323+
XMEMSET(clientPubKey, 0, sizeof(clientPubKey));
324+
XMEMSET(serverPubKey, 0, sizeof(serverPubKey));
321325
AssertIntEQ(0, wc_SrpInit(&cli, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
322326
AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA, SRP_SERVER_SIDE));
323327

@@ -388,6 +392,10 @@ static void test_SrpGetProofAndVerify(void)
388392
word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
389393
word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
390394

395+
XMEMSET(clientPubKey, 0, sizeof(clientPubKey));
396+
XMEMSET(serverPubKey, 0, sizeof(serverPubKey));
397+
XMEMSET(clientProof, 0, sizeof(clientProof));
398+
XMEMSET(serverProof, 0, sizeof(serverProof));
391399
AssertIntEQ(0, wc_SrpInit(&cli, SRP_TYPE_SHA, SRP_CLIENT_SIDE));
392400
AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA, SRP_SERVER_SIDE));
393401

@@ -792,6 +800,10 @@ static void test_SrpKeyGenFunc_cb(void)
792800
};
793801
#endif
794802

803+
XMEMSET(clientPubKey, 0, sizeof(clientPubKey));
804+
XMEMSET(serverPubKey, 0, sizeof(serverPubKey));
805+
XMEMSET(clientProof, 0, sizeof(clientProof));
806+
XMEMSET(serverProof, 0, sizeof(serverProof));
795807
AssertIntEQ(0, wc_SrpInit(&cli, SRP_TYPE_SHA512, SRP_CLIENT_SIDE));
796808
AssertIntEQ(0, wc_SrpInit(&srv, SRP_TYPE_SHA512, SRP_SERVER_SIDE));
797809

wolfcrypt/benchmark/benchmark.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4732,6 +4732,7 @@ void bench_chacha(void)
47324732
double start;
47334733
int i, count;
47344734

4735+
XMEMSET(&enc, 0, sizeof(enc));
47354736
wc_Chacha_SetKey(&enc, bench_key, 16);
47364737

47374738
bench_stats_start(&count, &start);

wolfcrypt/src/hpke.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ static int wc_HpkeContextOpenBase(Hpke* hpke, HpkeBaseContext* context,
11251125
return BAD_FUNC_ARG;
11261126
}
11271127

1128+
XMEMSET(nonce, 0, sizeof(nonce));
11281129
#ifdef WOLFSSL_SMALL_STACK
11291130
aes_key = (Aes*)XMALLOC(sizeof(Aes), hpke->heap, DYNAMIC_TYPE_AES);
11301131
if (aes_key == NULL) {

wolfcrypt/src/pkcs7.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8693,6 +8693,7 @@ static int wc_PKCS7_DecryptKtri(PKCS7* pkcs7, byte* in, word32 inSz,
86938693
mp_int serialNum[1];
86948694
RsaKey privKey[1];
86958695
#endif
8696+
XMEMSET(issuerHash, 0, sizeof(issuerHash));
86968697

86978698
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
86988699
keyIdSize = wc_HashGetDigestSize(wc_HashTypeConvert(HashIdAlg(

0 commit comments

Comments
 (0)