Fix malloc of zero size in fast_s_mp_sqr and fast_s_mp_mul_digs.

This commit is contained in:
jordan 2023-02-24 10:18:36 -06:00
parent b2a6203ec0
commit 22b1857bee

View File

@ -3335,6 +3335,12 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
if (pa > (int)MP_WARRAY)
return MP_RANGE; /* TAO range check */
if (pa == 0) {
/* Nothing to do. Zero result and return. */
mp_zero(b);
return MP_OKAY;
}
#ifdef WOLFSSL_SMALL_STACK
W = (mp_digit*)XMALLOC(sizeof(mp_digit) * pa, NULL, DYNAMIC_TYPE_BIGINT);
if (W == NULL)
@ -3454,6 +3460,12 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
if (pa > (int)MP_WARRAY)
return MP_RANGE; /* TAO range check */
if (pa == 0) {
/* Nothing to do. Zero result and return. */
mp_zero(c);
return MP_OKAY;
}
#ifdef WOLFSSL_SMALL_STACK
W = (mp_digit*)XMALLOC(sizeof(mp_digit) * pa, NULL, DYNAMIC_TYPE_BIGINT);
if (W == NULL)