Skip to content

Commit e175004

Browse files
committed
Fix Infer Uninitialized Values.
1 parent c8188ea commit e175004

7 files changed

Lines changed: 49 additions & 36 deletions

File tree

examples/pem/pem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ static int FindPem(char* data, word32 offset, word32 len, word32* start,
294294
word32* end, int* type)
295295
{
296296
int ret = 0;
297-
word32 i;
298-
word32 type_off;
297+
word32 i = 0;
298+
word32 type_off = 0;
299299
char str[PEM_TYPE_MAX_LEN];
300300

301301
/* Find header. */

src/ssl.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5610,7 +5610,8 @@ Signer* GetCAByName(void* vp, byte* hash)
56105610
/* add a trusted peer cert to linked list */
56115611
int AddTrustedPeer(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int verify)
56125612
{
5613-
int ret, row;
5613+
int ret = 0;
5614+
int row = 0;
56145615
TrustedPeerCert* peerCert;
56155616
DecodedCert* cert;
56165617
DerBuffer* der = *pDer;
@@ -9948,7 +9949,7 @@ static WOLFSSL_EVP_PKEY* _d2i_PublicKey(int type, WOLFSSL_EVP_PKEY** out,
99489949
word32 idx = 0, algId;
99499950
word16 pkcs8HeaderSz = 0;
99509951
WOLFSSL_EVP_PKEY* local;
9951-
int opt;
9952+
int opt = 0;
99529953

99539954
(void)opt;
99549955

@@ -10281,7 +10282,7 @@ int wolfSSL_use_RSAPrivateKey_ASN1(WOLFSSL* ssl, unsigned char* der, long derSz)
1028110282

1028210283
int wolfSSL_use_certificate(WOLFSSL* ssl, WOLFSSL_X509* x509)
1028310284
{
10284-
long idx;
10285+
long idx = 0;
1028510286

1028610287
WOLFSSL_ENTER("wolfSSL_use_certificate");
1028710288
if (x509 != NULL && ssl != NULL && x509->derCert != NULL) {
@@ -10527,7 +10528,7 @@ WOLFSSL_API int wolfSSL_get_negotiated_server_cert_type(WOLFSSL* ssl, int* tp)
1052710528
int wolfSSL_use_certificate_ASN1(WOLFSSL* ssl, const unsigned char* der,
1052810529
int derSz)
1052910530
{
10530-
long idx;
10531+
long idx = 0;
1053110532

1053210533
WOLFSSL_ENTER("wolfSSL_use_certificate_ASN1");
1053310534
if (der != NULL && ssl != NULL) {
@@ -11736,9 +11737,14 @@ static int wolfSSL_parse_cipher_list(WOLFSSL_CTX* ctx, Suites* suites,
1173611737
if (suites->suiteSz > 0) {
1173711738
suitesCpy = (byte*)XMALLOC(suites->suiteSz, NULL,
1173811739
DYNAMIC_TYPE_TMP_BUFFER);
11739-
if (suitesCpy == NULL)
11740+
if (suitesCpy == NULL) {
1174011741
return WOLFSSL_FAILURE;
11742+
}
11743+
11744+
XMEMSET(suitesCpy, 0, suites->suiteSz);
1174111745
}
11746+
#else
11747+
XMEMSET(suitesCpy, 0, sizeof(suitesCpy));
1174211748
#endif
1174311749

1174411750
if (suites->suiteSz > 0)
@@ -23151,7 +23157,7 @@ WOLFSSL_SESSION* wolfSSL_d2i_SSL_SESSION(WOLFSSL_SESSION** sess,
2315123157
WOLFSSL_SESSION* s = NULL;
2315223158
int ret = 0;
2315323159
#if defined(HAVE_EXT_CACHE)
23154-
int idx;
23160+
int idx = 0;
2315523161
byte* data;
2315623162
#ifdef SESSION_CERTS
2315723163
int j;
@@ -24529,7 +24535,7 @@ static int populate_groups(int* groups, int max_count, char *list)
2452924535
int wolfSSL_CTX_set1_groups_list(WOLFSSL_CTX *ctx, char *list)
2453024536
{
2453124537
int groups[WOLFSSL_MAX_GROUP_COUNT];
24532-
int count;
24538+
int count = 0;
2453324539

2453424540
if (!ctx || !list) {
2453524541
return WOLFSSL_FAILURE;
@@ -24546,7 +24552,7 @@ int wolfSSL_CTX_set1_groups_list(WOLFSSL_CTX *ctx, char *list)
2454624552
int wolfSSL_set1_groups_list(WOLFSSL *ssl, char *list)
2454724553
{
2454824554
int groups[WOLFSSL_MAX_GROUP_COUNT];
24549-
int count;
24555+
int count = 0;
2455024556

2455124557
if (!ssl || !list) {
2455224558
return WOLFSSL_FAILURE;
@@ -24770,7 +24776,7 @@ byte* wolfSSL_get_chain_cert(WOLFSSL_X509_CHAIN* chain, int idx)
2477024776
/* Get peer's wolfSSL X509 certificate at index (idx) */
2477124777
WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx)
2477224778
{
24773-
int ret;
24779+
int ret = 0;
2477424780
WOLFSSL_X509* x509 = NULL;
2477524781
#ifdef WOLFSSL_SMALL_STACK
2477624782
DecodedCert* cert = NULL;
@@ -28310,6 +28316,7 @@ static int wolfSSL_SESSION_print_ticket(WOLFSSL_BIO* bio,
2831028316

2831128317
for (i = 0; i < sz;) {
2831228318
char asc[16];
28319+
XMEMSET(asc, 0, sizeof(asc));
2831328320

2831428321
if (sz - i < 16) {
2831528322
if (wolfSSL_BIO_printf(bio, "%s%04X -", tab, tag + (sz - i)) <= 0)

src/wolfio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,9 @@ int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName, char* outPath,
14091409
word32 bigPort = 0;
14101410
i = 0;
14111411
cur++;
1412+
1413+
XMEMSET(port, 0, sizeof(port));
1414+
14121415
while (i < 6 && cur < urlSz && url[cur] != 0 && url[cur] != '/') {
14131416
port[i] = url[cur];
14141417
i++; cur++;

tests/api.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4705,7 +4705,7 @@ static int test_wolfSSL_EVP_PKEY_print_public(void)
47054705
WOLFSSL_EVP_PKEY* pkey = NULL;
47064706
char line[256] = { 0 };
47074707
char line1[256] = { 0 };
4708-
int i;
4708+
int i = 0;
47094709

47104710
/* test error cases */
47114711
ExpectIntEQ( EVP_PKEY_print_public(NULL,NULL,0,NULL),0L);
@@ -25739,7 +25739,7 @@ static int test_ToTraditional(void)
2573925739
defined(OPENSSL_EXTRA_X509_SMALL)) && !defined(NO_FILESYSTEM)
2574025740
XFILE f = XBADFILE;
2574125741
byte input[TWOK_BUF];
25742-
word32 sz;
25742+
word32 sz = 0;
2574325743

2574425744
ExpectTrue((f = XFOPEN("./certs/server-keyPkcs8.der", "rb")) != XBADFILE);
2574525745
ExpectTrue((sz = (word32)XFREAD(input, 1, sizeof(input), f)) > 0);
@@ -28151,10 +28151,10 @@ static int test_wc_PKCS7_EncodeEncryptedData(void)
2815128151
byte decoded[TWOK_BUF];
2815228152
word32 tmpWrd32 = 0;
2815328153
int tmpInt = 0;
28154-
int decodedSz;
28154+
int decodedSz = 0;
2815528155
int encryptedSz = 0;
28156-
int testSz;
28157-
int i;
28156+
int testSz = 0;
28157+
int i = 0;
2815828158
const byte data[] = { /* Hello World */
2815928159
0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
2816028160
0x72,0x6c,0x64
@@ -28766,7 +28766,7 @@ static int test_wc_PKCS7_signed_enveloped(void)
2876628766
word32 idx = 0;
2876728767
byte digest[MAX_SEQ_SZ + MAX_ALGO_SZ + MAX_OCTET_STR_SZ +
2876828768
WC_MAX_DIGEST_SIZE];
28769-
int digestSz;
28769+
int digestSz = 0;
2877028770

2877128771
ExpectIntEQ(wc_InitRsaKey(&rKey, HEAP_HINT), 0);
2877228772
ExpectIntEQ(wc_RsaPrivateKeyDecode(key, &idx, &rKey, keySz), 0);
@@ -29680,7 +29680,7 @@ static int test_wolfSSL_d2i_ASN1_INTEGER(void)
2968029680
const byte* p = NULL;
2968129681
byte* p2 = NULL;
2968229682
byte* reEncoded = NULL;
29683-
int reEncodedSz;
29683+
int reEncodedSz = 0;
2968429684

2968529685
static const byte zeroDer[] = {
2968629686
0x02, 0x01, 0x00
@@ -31026,8 +31026,8 @@ static int test_wolfSSL_ASN1_TIME_diff_compare(void)
3102631026
ASN1_TIME* closeToTime = NULL;
3102731027
ASN1_TIME* toTime = NULL;
3102831028
ASN1_TIME* invalidTime = NULL;
31029-
int daysDiff;
31030-
int secsDiff;
31029+
int daysDiff = 0;
31030+
int secsDiff = 0;
3103131031

3103231032
ExpectNotNull((fromTime = ASN1_TIME_new()));
3103331033
/* Feb 22, 2003, 21:15:15 */
@@ -31219,6 +31219,8 @@ static int test_wolfSSL_ASN1_TIME_to_tm(void)
3121931219
struct tm tm;
3122031220
time_t testTime = 1683926567; /* Fri May 12 09:22:47 PM UTC 2023 */
3122131221

31222+
XMEMSET(&tm, 0, sizeof(struct tm));
31223+
3122231224
XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
3122331225
ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515Z"), 1);
3122431226
ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, NULL), 1);
@@ -31626,7 +31628,7 @@ static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
3162631628
#if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
3162731629
EC_KEY *eckey = NULL;
3162831630
EVP_PKEY *key = NULL;
31629-
size_t len;
31631+
size_t len = 0;
3163031632
unsigned char *der = NULL;
3163131633
DPP_BOOTSTRAPPING_KEY *bootstrap = NULL;
3163231634
const unsigned char *in = ecc_clikey_der_256;
@@ -31950,7 +31952,7 @@ static int test_wolfSSL_X509_NAME_print_ex(void)
3195031952
defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
3195131953
defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))) && \
3195231954
!defined(NO_BIO) && !defined(NO_RSA)
31953-
int memSz;
31955+
int memSz = 0;
3195431956
byte* mem = NULL;
3195531957
BIO* bio = NULL;
3195631958
BIO* membio = NULL;
@@ -32113,7 +32115,7 @@ static int test_wolfSSL_X509_INFO_multiple_info(void)
3211332115
* to group objects together. */
3211432116
ExpectNotNull(concatBIO = BIO_new(BIO_s_mem()));
3211532117
for (curFile = files; EXPECT_SUCCESS() && *curFile != NULL; curFile++) {
32116-
int fileLen;
32118+
int fileLen = 0;
3211732119
ExpectNotNull(fileBIO = BIO_new_file(*curFile, "rb"));
3211832120
ExpectIntGT(fileLen = wolfSSL_BIO_get_len(fileBIO), 0);
3211932121
if (EXPECT_SUCCESS()) {
@@ -32459,7 +32461,7 @@ static int test_wc_KeyPemToDer(void)
3245932461
{
3246032462
EXPECT_DECLS;
3246132463
#if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
32462-
int ret;
32464+
int ret = 0;
3246332465
const byte cert_buf[] = \
3246432466
"-----BEGIN PRIVATE KEY-----\n"
3246532467
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMG5KgWxP002pA\n"
@@ -32830,7 +32832,7 @@ static int test_wolfSSL_certs(void)
3283032832
ASN1_STRING* asn1_str = NULL;
3283132833
AUTHORITY_KEYID* akey = NULL;
3283232834
BASIC_CONSTRAINTS* bc = NULL;
32833-
int crit;
32835+
int crit = 0;
3283432836

3283532837
#ifndef NO_WOLFSSL_SERVER
3283632838
ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
@@ -33342,7 +33344,7 @@ static int test_wolfSSL_PEM_read_PrivateKey(void)
3334233344
RSA* rsa = NULL;
3334333345
WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
3334433346
unsigned char* sig = NULL;
33345-
size_t sigLen;
33347+
size_t sigLen = 0;
3334633348
const unsigned char tbs[] = {0, 1, 2, 3, 4, 5, 6, 7};
3334733349
size_t tbsLen = sizeof(tbs);
3334833350

@@ -33417,7 +33419,7 @@ static int test_wolfSSL_PEM_PrivateKey(void)
3341733419
const char* fname = "./certs/server-key.pem";
3341833420
const char* fname_rsa_p8 = "./certs/server-keyPkcs8.pem";
3341933421

33420-
size_t sz;
33422+
size_t sz = 0;
3342133423
byte* buf = NULL;
3342233424
EVP_PKEY* pkey2 = NULL;
3342333425
EVP_PKEY* pkey3 = NULL;
@@ -62375,7 +62377,7 @@ static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_server_thread(void* args)
6237562377
char msg[] = "I hear you fa shizzle!";
6237662378
int len = (int) XSTRLEN(msg);
6237762379
char input[1024];
62378-
int ret;
62380+
int ret = 0;
6237962381
int err = 0;
6238062382

6238162383
if (!args)

wolfcrypt/src/asn.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12947,7 +12947,7 @@ static const byte rdnChoice[] = {
1294712947
static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap)
1294812948
{
1294912949
int ret = 0;
12950-
size_t nameSz;
12950+
size_t nameSz = 0;
1295112951
char tmpName[WOLFSSL_MAX_IPSTR] = {0};
1295212952
unsigned char* ip;
1295312953

@@ -26980,8 +26980,8 @@ static int EncodeName(EncodedName* name, const char* nameStr,
2698026980
int ret = 0;
2698126981
int sz = 0;
2698226982
const byte* oid;
26983-
word32 oidSz;
26984-
word32 nameSz;
26983+
word32 oidSz = 0;
26984+
word32 nameSz = 0;
2698526985

2698626986
/* Validate input parameters. */
2698726987
if ((name == NULL) || (nameStr == NULL)) {
@@ -27758,7 +27758,7 @@ static int EncodeExtensions(Cert* cert, byte* output, word32 maxSz,
2775827758
int forRequest)
2775927759
{
2776027760
DECL_ASNSETDATA(dataASN, certExtsASN_Length);
27761-
int sz;
27761+
int sz = 0;
2776227762
int ret = 0;
2776327763
int i = 0;
2776427764
static const byte bcOID[] = { 0x55, 0x1d, 0x13 };
@@ -35073,7 +35073,8 @@ static int DecodeResponseData(byte* source, word32* ioIndex,
3507335073
DECL_ASNGETDATA(dataASN, ocspRespDataASN_Length);
3507435074
int ret = 0;
3507535075
byte version;
35076-
word32 dateSz, idx = *ioIndex;
35076+
word32 dateSz = 0;
35077+
word32 idx = *ioIndex;
3507735078
OcspEntry* single = NULL;
3507835079

3507935080
WOLFSSL_ENTER("DecodeResponseData");

wolfcrypt/src/pkcs7.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,8 +4280,8 @@ static int wc_PKCS7_ParseSignerInfo(PKCS7* pkcs7, byte* in, word32 inSz,
42804280
word32* idxIn, int degenerate, byte** signedAttrib, int* signedAttribSz)
42814281
{
42824282
int ret = 0;
4283-
int length;
4284-
int version;
4283+
int length = 0;
4284+
int version = 0;
42854285
word32 sigOID = 0, hashOID = 0;
42864286
word32 idx = *idxIn, localIdx;
42874287
byte tag;

wolfcrypt/test/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33006,7 +33006,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void)
3300633006
#ifdef HAVE_CURVE448_KEY_EXPORT
3300733007
byte exportBuf[CURVE448_KEY_SIZE];
3300833008
#endif
33009-
word32 x;
33009+
word32 x = 0;
3301033010
curve448_key userA, userB, pubKey;
3301133011

3301233012
#if defined(HAVE_CURVE448_SHARED_SECRET) && \

0 commit comments

Comments
 (0)