make sure mp_init return always checked

This commit is contained in:
toddouska 2012-08-27 11:30:22 -07:00
parent 0534d44c9e
commit 30a264eb65
3 changed files with 24 additions and 10 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -6121,8 +6121,11 @@ static int initGlobalRNG = 0;
}
InitCyaSSL_BigNum(external);
mp_init(mpi);
external->internal = mpi;
if (mp_init(mpi) != MP_OKAY) {
CyaSSL_BN_free(external);
return NULL;
}
return external;
}