Skip to content

Commit b66f1b7

Browse files
committed
peer/Devin review:
* in get_crypto_default_rng() (linuxkm/lkcapi_sha_glue.c), sanity check that crypto_default_rng isn't null; * in wc_InitRsaKey_ex(), remove frivolous NULL/zero assignments (XMEMSET clears them implicitly); * in wc_CheckRsaKey(), check ret from wc_InitRng() and short circuit return if failed.
1 parent da4fc49 commit b66f1b7

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

linuxkm/lkcapi_sha_glue.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,11 @@ static inline void put_drbg(struct wc_rng_inst *drbg) {
11341134
static inline struct crypto_rng *get_crypto_default_rng(void) {
11351135
struct crypto_rng *current_crypto_default_rng = crypto_default_rng;
11361136

1137+
if (unlikely(! current_crypto_default_rng)) {
1138+
pr_warn("BUG: get_default_drbg_ctx() called with NULL crypto_default_rng.");
1139+
return NULL;
1140+
}
1141+
11371142
if (unlikely(! wc_linuxkm_drbg_default_instance_registered)) {
11381143
pr_warn("BUG: get_default_drbg_ctx() called without wc_linuxkm_drbg_default_instance_registered.");
11391144
return NULL;

wolfcrypt/src/rsa.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,6 @@ int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
201201
(!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE)))
202202
key->dataIsAlloc = 0;
203203
#endif
204-
key->data = NULL;
205-
key->dataLen = 0;
206-
#ifdef WC_RSA_BLINDING
207-
key->rng = NULL;
208-
#endif
209204

210205
#ifdef WOLF_CRYPTO_CB
211206
key->devId = devId;
@@ -741,6 +736,13 @@ int wc_CheckRsaKey(RsaKey* key)
741736
}
742737
#endif
743738
ret = wc_InitRng(rng);
739+
if (ret != 0) {
740+
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
741+
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
742+
FREE_MP_INT_SIZE(tmp, NULL, DYNAMIC_TYPE_RSA);
743+
#endif
744+
return ret;
745+
}
744746
}
745747

746748
SAVE_VECTOR_REGISTERS(ret = _svr_ret;);

0 commit comments

Comments
 (0)