Skip to content

Commit ae6f471

Browse files
committed
Add robustness checks
1 parent 1dc4d0e commit ae6f471

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/wp_ecdh_exch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ static wp_EcdhCtx* wp_ecdh_dup(wp_EcdhCtx* src)
156156
}
157157
if (!ok) {
158158
/* Free allocated memory and up referenced objects. */
159-
wp_ecc_free(src->peer);
160-
wp_ecc_free(src->key);
159+
wp_ecc_free(dst->peer);
160+
wp_ecc_free(dst->key);
161161
OPENSSL_free(dst);
162162
dst = NULL;
163163
}

src/wp_ecx_exch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ static wp_EcxCtx* wp_ecx_dupctx(wp_EcxCtx* src)
115115
dst->peer = src->peer;
116116
}
117117
if (!ok) {
118-
wp_ecx_free(src->key);
118+
wp_ecx_free(dst->key);
119+
wp_ecx_free(dst->peer);
119120
OPENSSL_free(dst);
120121
dst = NULL;
121122
}

src/wp_internal.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,13 @@ int wp_unlock(wolfSSL_Mutex* mutex)
332332
*/
333333
int wp_name_to_nid(OSSL_LIB_CTX* libCtx, const char* name, const char* propQ)
334334
{
335-
int nid;
335+
int nid = NID_undef;
336336

337337
EVP_MD* md = EVP_MD_fetch(libCtx, name, propQ);
338-
nid = EVP_MD_type(md);
339-
EVP_MD_free(md);
340-
338+
if (md) {
339+
nid = EVP_MD_type(md);
340+
EVP_MD_free(md);
341+
}
341342
return nid;
342343
}
343344

@@ -441,11 +442,13 @@ enum wc_HashType wp_nid_to_wc_hash_type(int nid)
441442
int wp_name_to_wc_mgf(OSSL_LIB_CTX* libCtx, const char* name,
442443
const char* propQ)
443444
{
444-
int ret;
445+
int ret = WC_MGF1NONE;
445446

446447
EVP_MD* md = EVP_MD_fetch(libCtx, name, propQ);
447-
ret = wp_mgf1_from_hash(EVP_MD_type(md));
448-
EVP_MD_free(md);
448+
if (md) {
449+
ret = wp_mgf1_from_hash(EVP_MD_type(md));
450+
EVP_MD_free(md);
451+
}
449452

450453
return ret;
451454
}

src/wp_kbkdf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ static int wp_kbkdf_init_hmac(wp_KbkdfCtx* ctx, unsigned char* key,
394394
localKeyLen = (word32)keyLen;
395395
}
396396

397+
if (localKeyLen > sizeof(localKey)) {
398+
ok = 0;
399+
}
400+
397401
if (ok) {
398402
XMEMCPY(localKey, key, keyLen);
399403
rc = wc_HmacSetKey(&ctx->hmacCtx, ctx->hashType, localKey,

0 commit comments

Comments
 (0)