Skip to content

Commit b535d9f

Browse files
Merge pull request #8093 from philljj/fix_coverity
Fix coverity
2 parents 104c805 + 5690af8 commit b535d9f

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

src/internal.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13587,21 +13587,28 @@ static int ProcessCSR_ex(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1358713587

1358813588
#ifdef WOLFSSL_SMALL_STACK
1358913589
status = (CertStatus*)XMALLOC(sizeof(CertStatus), ssl->heap,
13590-
DYNAMIC_TYPE_OCSP_STATUS);
13590+
DYNAMIC_TYPE_OCSP_STATUS);
1359113591
single = (OcspEntry*)XMALLOC(sizeof(OcspEntry), ssl->heap,
13592-
DYNAMIC_TYPE_OCSP_ENTRY);
13592+
DYNAMIC_TYPE_OCSP_ENTRY);
1359313593
response = (OcspResponse*)XMALLOC(sizeof(OcspResponse), ssl->heap,
13594-
DYNAMIC_TYPE_OCSP_REQUEST);
13594+
DYNAMIC_TYPE_OCSP_REQUEST);
1359513595

1359613596
if (status == NULL || single == NULL || response == NULL) {
13597-
XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
13598-
XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
13599-
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
13597+
if (status != NULL) {
13598+
XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
13599+
}
13600+
if (single != NULL) {
13601+
XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
13602+
}
13603+
if (response != NULL) {
13604+
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
13605+
}
1360013606

1360113607
return MEMORY_ERROR;
1360213608
}
1360313609
#endif
1360413610

13611+
/* InitOcspResponse sets single and status to response struct. */
1360513612
InitOcspResponse(response, single, status, input +*inOutIdx, status_length, ssl->heap);
1360613613

1360713614
if (OcspResponseDecode(response, SSL_CM(ssl), ssl->heap, 0) != 0)
@@ -13622,12 +13629,14 @@ static int ProcessCSR_ex(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1362213629

1362313630
*inOutIdx += status_length;
1362413631

13632+
/* FreeOcspResponse frees status and single only if
13633+
* single->isDynamic is set. */
1362513634
FreeOcspResponse(response);
1362613635

1362713636
#ifdef WOLFSSL_SMALL_STACK
13628-
XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
13629-
XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
13630-
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
13637+
XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
13638+
XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
13639+
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
1363113640
#endif
1363213641

1363313642
WOLFSSL_LEAVE("ProcessCSR", ret);

wolfcrypt/src/sp_int.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12429,8 +12429,10 @@ static int _sp_invmod_div(const sp_int* a, const sp_int* m, sp_int* x,
1242912429

1243012430
ALLOC_SP_INT(d, m->used + 1, err, NULL);
1243112431
if (err == MP_OKAY) {
12432-
sp_init_size(d, m->used + 1);
12432+
err = sp_init_size(d, m->used + 1);
12433+
}
1243312434

12435+
if (err == MP_OKAY) {
1243412436
/* 1. x = m, y = a, b = 1, c = 0 */
1243512437
if (a != y) {
1243612438
_sp_copy(a, y);

wolfcrypt/test/test.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33731,6 +33731,8 @@ static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
3373133731
word32 plaintextLen;
3373233732
word32 encryptLen = MAX_ECIES_TEST_SZ;
3373333733
word32 decryptLen = MAX_ECIES_TEST_SZ;
33734+
int aInit = 0;
33735+
int bInit = 0;
3373433736

3373533737
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
3373633738
plaintext = XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
@@ -33742,12 +33744,22 @@ static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
3374233744
wc_ecc_free(b);
3374333745

3374433746
ret = wc_ecc_init(a);
33745-
if (ret != 0)
33747+
if (ret != 0) {
3374633748
ret = WC_TEST_RET_ENC_EC(ret);
33749+
}
33750+
else {
33751+
aInit = 1;
33752+
}
33753+
33754+
3374733755
if (ret == 0) {
3374833756
ret = wc_ecc_init(b);
33749-
if (ret != 0)
33757+
if (ret != 0) {
3375033758
ret = WC_TEST_RET_ENC_EC(ret);
33759+
}
33760+
else {
33761+
bInit = 1;
33762+
}
3375133763
}
3375233764

3375333765
if (ret == 0)
@@ -33809,8 +33821,13 @@ static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
3380933821
if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
3381033822
ret = WC_TEST_RET_ENC_NC;
3381133823

33812-
wc_ecc_free(a);
33813-
wc_ecc_free(b);
33824+
if (aInit) {
33825+
wc_ecc_free(a);
33826+
}
33827+
33828+
if (bInit) {
33829+
wc_ecc_free(b);
33830+
}
3381433831

3381533832
wc_ecc_ctx_free(aCtx);
3381633833
wc_ecc_ctx_free(bCtx);

0 commit comments

Comments
 (0)