Skip to content

Commit 9b92b4c

Browse files
authored
Merge pull request #8962 from rlm2002/coverity
Coverity: Dereference after NULL check and Use after free
2 parents a40b56c + de59e9d commit 9b92b4c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/internal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6468,6 +6468,10 @@ int DhGenKeyPair(WOLFSSL* ssl, DhKey* dhKey,
64686468

64696469
WOLFSSL_ENTER("DhGenKeyPair");
64706470

6471+
if (ssl == NULL || dhKey == NULL) {
6472+
return BAD_FUNC_ARG;
6473+
}
6474+
64716475
#ifdef WOLFSSL_ASYNC_CRYPT
64726476
/* initialize event */
64736477
ret = wolfSSL_AsyncInit(ssl, &dhKey->asyncDev, WC_ASYNC_FLAG_NONE);

tests/api.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19598,6 +19598,9 @@ static int test_wolfSSL_d2i_ASN1_INTEGER(void)
1959819598
a->isDynamic = 0;
1959919599
a->data = a->intData;
1960019600
}
19601+
/* Reset p2 to NULL. */
19602+
XFREE(p2, NULL, DYNAMIC_TYPE_ASN1);
19603+
1960119604
/* Set a to valid value. */
1960219605
ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(a, 1), WOLFSSL_SUCCESS);
1960319606
/* NULL output buffer. */
@@ -19637,7 +19640,6 @@ static int test_wolfSSL_d2i_ASN1_INTEGER(void)
1963719640
reEncoded = NULL;
1963819641
wolfSSL_ASN1_INTEGER_free(a);
1963919642
a = NULL;
19640-
p2 = NULL;
1964119643
}
1964219644
#endif /* OPENSSL_EXTRA */
1964319645
return EXPECT_RESULT();
@@ -38171,7 +38173,8 @@ static int test_wolfSSL_BIO_write(void)
3817138173
ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
3817238174
ExpectNotNull(bio = BIO_push(BIO_new(BIO_f_base64()), bio64));
3817338175
if (EXPECT_FAIL()) {
38174-
BIO_free(bio64);
38176+
BIO_free_all(bio);
38177+
bio = NULL;
3817538178
bio64 = NULL;
3817638179
}
3817738180
ExpectNotNull(bio_mem = BIO_new(BIO_s_mem()));
@@ -38181,6 +38184,9 @@ static int test_wolfSSL_BIO_write(void)
3818138184
}
3818238185

3818338186
/* now should convert to base64 when stored and then decode with read */
38187+
if (bio == NULL) {
38188+
ExpectNotNull(bio = BIO_new(BIO_f_base64()));
38189+
}
3818438190
ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
3818538191
BIO_flush(bio);
3818638192
sz = sizeof(out);

0 commit comments

Comments
 (0)