mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-04-30 03:34:39 +00:00
Added NULL check to BN_clear() & BN_CTX_end()
Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/8518)
This commit is contained in:
parent
226f2bf191
commit
ce1415ed2c
@ -184,6 +184,8 @@ void BN_CTX_start(BN_CTX *ctx)
|
|||||||
|
|
||||||
void BN_CTX_end(BN_CTX *ctx)
|
void BN_CTX_end(BN_CTX *ctx)
|
||||||
{
|
{
|
||||||
|
if (ctx == NULL)
|
||||||
|
return;
|
||||||
CTXDBG("ENTER BN_CTX_end()", ctx);
|
CTXDBG("ENTER BN_CTX_end()", ctx);
|
||||||
if (ctx->err_stack)
|
if (ctx->err_stack)
|
||||||
ctx->err_stack--;
|
ctx->err_stack--;
|
||||||
|
@ -338,6 +338,8 @@ void BN_swap(BIGNUM *a, BIGNUM *b)
|
|||||||
|
|
||||||
void BN_clear(BIGNUM *a)
|
void BN_clear(BIGNUM *a)
|
||||||
{
|
{
|
||||||
|
if (a == NULL)
|
||||||
|
return;
|
||||||
bn_check_top(a);
|
bn_check_top(a);
|
||||||
if (a->d != NULL)
|
if (a->d != NULL)
|
||||||
OPENSSL_cleanse(a->d, sizeof(*a->d) * a->dmax);
|
OPENSSL_cleanse(a->d, sizeof(*a->d) * a->dmax);
|
||||||
|
@ -170,7 +170,6 @@ int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,
|
|||||||
found = 1;
|
found = 1;
|
||||||
err:
|
err:
|
||||||
OPENSSL_free(mods);
|
OPENSSL_free(mods);
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
bn_check_top(ret);
|
bn_check_top(ret);
|
||||||
|
@ -58,10 +58,8 @@ int DH_check_params(const DH *dh, int *ret)
|
|||||||
|
|
||||||
ok = 1;
|
ok = 1;
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL) {
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
}
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,10 +169,8 @@ int DH_check(const DH *dh, int *ret)
|
|||||||
}
|
}
|
||||||
ok = 1;
|
ok = 1;
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL) {
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
}
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,9 +221,7 @@ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
|
|||||||
|
|
||||||
ok = 1;
|
ok = 1;
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL) {
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
}
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
@ -122,9 +122,7 @@ static int dh_builtin_genparams(DH *ret, int prime_len, int generator,
|
|||||||
ok = 0;
|
ok = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx != NULL) {
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
}
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
@ -205,10 +205,8 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
|
|||||||
|
|
||||||
ret = BN_bn2bin(tmp, key);
|
ret = BN_bn2bin(tmp, key);
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL) {
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +292,6 @@ int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
|
|||||||
if (seed_out)
|
if (seed_out)
|
||||||
memcpy(seed_out, seed, qsize);
|
memcpy(seed_out, seed, qsize);
|
||||||
}
|
}
|
||||||
if (ctx)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
BN_MONT_CTX_free(mont);
|
BN_MONT_CTX_free(mont);
|
||||||
@ -607,7 +606,6 @@ int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,
|
|||||||
OPENSSL_free(seed);
|
OPENSSL_free(seed);
|
||||||
if (seed_out != seed_tmp)
|
if (seed_out != seed_tmp)
|
||||||
OPENSSL_free(seed_tmp);
|
OPENSSL_free(seed_tmp);
|
||||||
if (ctx)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
BN_MONT_CTX_free(mont);
|
BN_MONT_CTX_free(mont);
|
||||||
|
@ -204,7 +204,6 @@ int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group,
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(new_ctx);
|
BN_CTX_free(new_ctx);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1079,7 +1079,6 @@ static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r,
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(new_ctx);
|
BN_CTX_free(new_ctx);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -948,7 +948,6 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(new_ctx);
|
BN_CTX_free(new_ctx);
|
||||||
EC_ec_pre_comp_free(pre_comp);
|
EC_ec_pre_comp_free(pre_comp);
|
||||||
|
@ -113,7 +113,6 @@ int ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen,
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
EC_POINT_clear_free(tmp);
|
EC_POINT_clear_free(tmp);
|
||||||
if (ctx)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
OPENSSL_free(buf);
|
OPENSSL_free(buf);
|
||||||
|
@ -888,7 +888,6 @@ __owur static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(new_ctx);
|
BN_CTX_free(new_ctx);
|
||||||
|
|
||||||
|
@ -307,7 +307,6 @@ int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(new_ctx);
|
BN_CTX_free(new_ctx);
|
||||||
return ret;
|
return ret;
|
||||||
@ -787,7 +786,6 @@ int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (ctx) /* otherwise we already called BN_CTX_end */
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(new_ctx);
|
BN_CTX_free(new_ctx);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -393,7 +393,6 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, int primes, BIGNUM *e_value,
|
|||||||
RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN);
|
RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN);
|
||||||
ok = 0;
|
ok = 0;
|
||||||
}
|
}
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
return ok;
|
return ok;
|
||||||
|
@ -148,7 +148,6 @@ static int rsa_ossl_public_encrypt(int flen, const unsigned char *from,
|
|||||||
*/
|
*/
|
||||||
r = BN_bn2binpad(ret, to, num);
|
r = BN_bn2binpad(ret, to, num);
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
OPENSSL_clear_free(buf, num);
|
OPENSSL_clear_free(buf, num);
|
||||||
@ -354,7 +353,6 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from,
|
|||||||
*/
|
*/
|
||||||
r = BN_bn2binpad(res, to, num);
|
r = BN_bn2binpad(res, to, num);
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
OPENSSL_clear_free(buf, num);
|
OPENSSL_clear_free(buf, num);
|
||||||
@ -484,7 +482,6 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
|
|||||||
err_clear_last_constant_time(r >= 0);
|
err_clear_last_constant_time(r >= 0);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
OPENSSL_clear_free(buf, num);
|
OPENSSL_clear_free(buf, num);
|
||||||
@ -581,7 +578,6 @@ static int rsa_ossl_public_decrypt(int flen, const unsigned char *from,
|
|||||||
RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
|
RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ctx != NULL)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
OPENSSL_clear_free(buf, num);
|
OPENSSL_clear_free(buf, num);
|
||||||
|
@ -133,7 +133,6 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
|
|||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
err:
|
err:
|
||||||
if (ctx)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
BN_CTX_free(ctx2);
|
BN_CTX_free(ctx2);
|
||||||
@ -188,7 +187,6 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
|
|||||||
ok = 1;
|
ok = 1;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (ctx)
|
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user