Sanity check NULL dereference.

This commit is contained in:
Stanislav Klima
2020-02-05 16:59:20 +01:00
parent c938cb35ca
commit bbfefd3cde

View File

@ -2846,6 +2846,14 @@ int mp_set_bit (mp_int * a, int b)
{
int i = b / DIGIT_BIT, res;
/*
* Require:
* bit index b >= 0
* a->alloc == a->used == 0 if a->dp == NULL
*/
if (b < 0 || (a->dp == NULL && (a->alloc != 0 || a->used != 0)))
return MP_VAL;
if (a->dp == NULL || a->used < (int)(i + 1)) {
/* grow a to accommodate the single bit */
if ((res = mp_grow (a, i + 1)) != MP_OKAY) {