Merge pull request #6133 from philljj/zd15662

Fix malloc of zero size in fast_s_mp_sqr and fast_s_mp_mul_digs.
This commit is contained in:
David Garske 2023-02-27 10:47:29 -08:00 committed by GitHub
commit 950e0d100a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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)