Skip to content

Commit 50a7243

Browse files
fix for coverity issue 394670 possible overflow
1 parent fbdb064 commit 50a7243

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/ssl_load.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5563,7 +5563,7 @@ long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL_DH* dh)
55635563
ret = wolfssl_ctx_set_tmp_dh(ctx, p, pSz, g, gSz);
55645564
}
55655565

5566-
if (ret != 1) {
5566+
if (ret != 1 && ctx != NULL) {
55675567
/* Free the allocated buffers if not assigned into SSL. */
55685568
XFREE(p, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);
55695569
XFREE(g, ctx->heap, DYNAMIC_TYPE_PUBLIC_KEY);

wolfcrypt/src/dh.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,6 +2940,14 @@ int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh)
29402940
if (ret == 0) {
29412941
/* modulus size in bytes */
29422942
modSz /= WOLFSSL_BIT_SIZE;
2943+
2944+
if ((word32)modSz < groupSz) {
2945+
WOLFSSL_MSG("DH modSz was too small");
2946+
ret = BAD_FUNC_ARG;
2947+
}
2948+
}
2949+
2950+
if (ret == 0) {
29432951
bufSz = (word32)modSz - groupSz;
29442952

29452953
/* allocate ram */

wolfcrypt/test/test.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22272,6 +22272,11 @@ static wc_test_ret_t dh_generate_test(WC_RNG *rng)
2227222272
if (ret != 0)
2227322273
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
2227422274

22275+
/* should fail since modSz is 16 and group size is 20 */
22276+
ret = wc_DhGenerateParams(rng, 128, smallKey);
22277+
if (ret == 0)
22278+
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
22279+
2227522280
ret = wc_DhGenerateParams(rng, 2056, smallKey);
2227622281
if (ret != 0)
2227722282
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);

0 commit comments

Comments
 (0)