Fix possible segfault occurs when mp_clear() is executed for uninitialized mp_int

If NULL is passed as the digest argument of wc_DsaSign(), mp_clear() will be
called before mp_init() is called. This can cause segmentation fault.

Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
This commit is contained in:
Masashi Honma
2021-11-16 09:35:10 +09:00
parent f621defefe
commit 6086728968

View File

@@ -664,14 +664,12 @@ int wc_DsaSign(const byte* digest, byte* out, DsaKey* key, WC_RNG* rng)
int ret = 0, halfSz = 0;
byte* tmp; /* initial output pointer */
if (digest == NULL || out == NULL || key == NULL || rng == NULL)
return BAD_FUNC_ARG;
SAVE_VECTOR_REGISTERS(return _svr_ret;);
do {
if (digest == NULL || out == NULL || key == NULL || rng == NULL) {
ret = BAD_FUNC_ARG;
break;
}
#ifdef WOLFSSL_SMALL_STACK
k = (mp_int *)XMALLOC(sizeof *k, key->heap, DYNAMIC_TYPE_TMP_BUFFER);
kInv = (mp_int *)XMALLOC(sizeof *kInv, key->heap,