make sure mp_init return always checked
This commit is contained in:
parent
0534d44c9e
commit
30a264eb65
@ -433,7 +433,9 @@ static int GetInt(mp_int* mpi, const byte* input, word32* inOutIdx,
|
||||
else
|
||||
i--;
|
||||
|
||||
mp_init(mpi);
|
||||
if (mp_init(mpi) != MP_OKAY)
|
||||
return MP_INIT_E;
|
||||
|
||||
if (mp_read_unsigned_bin(mpi, (byte*)input + i, length) != 0) {
|
||||
mp_clear(mpi);
|
||||
return ASN_GETINT_E;
|
||||
@ -928,14 +930,19 @@ int DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g, word32 gSz)
|
||||
gSz--; g++;
|
||||
}
|
||||
|
||||
mp_init(&key->p);
|
||||
if (mp_init(&key->p) != MP_OKAY)
|
||||
return MP_INIT_E;
|
||||
if (mp_read_unsigned_bin(&key->p, p, pSz) != 0) {
|
||||
mp_clear(&key->p);
|
||||
return ASN_DH_KEY_E;
|
||||
}
|
||||
|
||||
mp_init(&key->g);
|
||||
if (mp_init(&key->g) != MP_OKAY) {
|
||||
mp_clear(&key->p);
|
||||
return MP_INIT_E;
|
||||
}
|
||||
if (mp_read_unsigned_bin(&key->g, g, gSz) != 0) {
|
||||
mp_clear(&key->g);
|
||||
mp_clear(&key->p);
|
||||
return ASN_DH_KEY_E;
|
||||
}
|
||||
|
@ -261,11 +261,14 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt,
|
||||
for (i = 0; i < (int)v; i++)
|
||||
B[i] = Ai[i % u];
|
||||
|
||||
mp_init(&B1);
|
||||
if (mp_read_unsigned_bin(&B1, B, v) != MP_OKAY)
|
||||
if (mp_init(&B1) != MP_OKAY)
|
||||
ret = MP_INIT_E;
|
||||
else if (mp_read_unsigned_bin(&B1, B, v) != MP_OKAY)
|
||||
ret = MP_READ_E;
|
||||
else if (mp_add_d(&B1, (mp_digit)1, &B1) != MP_OKAY) {
|
||||
else if (mp_add_d(&B1, (mp_digit)1, &B1) != MP_OKAY)
|
||||
ret = MP_ADD_E;
|
||||
|
||||
if (ret != 0) {
|
||||
mp_clear(&B1);
|
||||
break;
|
||||
}
|
||||
@ -275,9 +278,10 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt,
|
||||
mp_int i1;
|
||||
mp_int res;
|
||||
|
||||
mp_init(&i1);
|
||||
mp_init(&res);
|
||||
|
||||
if (mp_init_multi(&i1, &res, NULL, NULL, NULL, NULL) != MP_OKAY) {
|
||||
ret = MP_INIT_E;
|
||||
break;
|
||||
}
|
||||
if (mp_read_unsigned_bin(&i1, I + i, v) != MP_OKAY)
|
||||
ret = MP_READ_E;
|
||||
else if (mp_add(&i1, &B1, &res) != MP_OKAY)
|
||||
|
Loading…
Reference in New Issue
Block a user