diff options
80 files changed, 385 insertions, 734 deletions
diff --git a/apps/apps.c b/apps/apps.c index 904629b2f1..d68594ab27 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -1532,6 +1532,7 @@ int rand_serial(BIGNUM *b, ASN1_INTEGER *ai) { BIGNUM *btmp; int ret = 0; + if (b) btmp = b; else @@ -1549,7 +1550,7 @@ int rand_serial(BIGNUM *b, ASN1_INTEGER *ai) error: - if (!b) + if (btmp != b) BN_free(btmp); return ret; @@ -1289,10 +1289,8 @@ end_of_options: if (!save_serial(crlnumberfile, "new", crlnumber, NULL)) goto end; - if (crlnumber) { - BN_free(crlnumber); - crlnumber = NULL; - } + BN_free(crlnumber); + crlnumber = NULL; if (!do_X509_CRL_sign(crl, pkey, dgst, sigopts)) goto end; diff --git a/apps/dsaparam.c b/apps/dsaparam.c index afc8a82b01..62d5fe7a41 100644 --- a/apps/dsaparam.c +++ b/apps/dsaparam.c @@ -328,8 +328,7 @@ int dsaparam_main(int argc, char **argv) app_RAND_write_file(NULL); ret = 0; end: - if (cb != NULL) - BN_GENCB_free(cb); + BN_GENCB_free(cb); BIO_free(in); BIO_free_all(out); DSA_free(dsa); diff --git a/apps/ecparam.c b/apps/ecparam.c index 5b39e83cd8..082df260ab 100644 --- a/apps/ecparam.c +++ b/apps/ecparam.c @@ -483,18 +483,12 @@ int ecparam_main(int argc, char **argv) ret = 0; end: - if (ec_p) - BN_free(ec_p); - if (ec_a) - BN_free(ec_a); - if (ec_b) - BN_free(ec_b); - if (ec_gen) - BN_free(ec_gen); - if (ec_order) - BN_free(ec_order); - if (ec_cofactor) - BN_free(ec_cofactor); + BN_free(ec_p); + BN_free(ec_a); + BN_free(ec_b); + BN_free(ec_gen); + BN_free(ec_order); + BN_free(ec_cofactor); if (buffer) OPENSSL_free(buffer); BIO_free(in); diff --git a/apps/genrsa.c b/apps/genrsa.c index 7d0466aaf9..a3c00d871e 100644 --- a/apps/genrsa.c +++ b/apps/genrsa.c @@ -214,10 +214,8 @@ int genrsa_main(int argc, char **argv) ret = 0; end: - if (bn) - BN_free(bn); - if (cb) - BN_GENCB_free(cb); + BN_free(bn); + BN_GENCB_free(cb); RSA_free(rsa); BIO_free_all(out); if (passout) diff --git a/apps/s_client.c b/apps/s_client.c index e7e66849d1..8d8340d311 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -241,8 +241,7 @@ static unsigned int psk_client_cb(SSL *ssl, const char *hint, char *identity, if (!ret) { BIO_printf(bio_err, "Could not convert PSK key '%s' to BIGNUM\n", psk_key); - if (bn) - BN_free(bn); + BN_free(bn); return 0; } @@ -320,12 +319,9 @@ static int srp_Verify_N_and_g(const BIGNUM *N, const BIGNUM *g) BN_mod_exp(r, g, p, N, bn_ctx) && BN_add_word(r, 1) && BN_cmp(r, N) == 0; - if (r) - BN_free(r); - if (p) - BN_free(p); - if (bn_ctx) - BN_CTX_free(bn_ctx); + BN_free(r); + BN_free(p); + BN_CTX_free(bn_ctx); return ret; } diff --git a/apps/s_server.c b/apps/s_server.c index ef32d5a9b0..a616b64a11 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -315,8 +315,7 @@ static unsigned int psk_server_cb(SSL *ssl, const char *identity, if (!ret) { BIO_printf(bio_err, "Could not convert PSK key '%s' to BIGNUM\n", psk_key); - if (bn) - BN_free(bn); + BN_free(bn); return 0; } if (BN_num_bytes(bn) > (int)max_psk_len) { diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c index 2b5a4940fe..1e76122192 100644 --- a/crypto/asn1/a_object.c +++ b/crypto/asn1/a_object.c @@ -201,14 +201,12 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) } if (tmp != ftmp) OPENSSL_free(tmp); - if (bl) - BN_free(bl); + BN_free(bl); return (len); err: if (tmp != ftmp) OPENSSL_free(tmp); - if (bl) - BN_free(bl); + BN_free(bl); return (0); } diff --git a/crypto/bn/bn_blind.c b/crypto/bn/bn_blind.c index f045904f76..659638bc45 100644 --- a/crypto/bn/bn_blind.c +++ b/crypto/bn/bn_blind.c @@ -166,8 +166,7 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod) CRYPTO_THREADID_current(&ret->tid); return (ret); err: - if (ret != NULL) - BN_BLINDING_free(ret); + BN_BLINDING_free(ret); return (NULL); } @@ -176,14 +175,10 @@ void BN_BLINDING_free(BN_BLINDING *r) if (r == NULL) return; - if (r->A != NULL) - BN_free(r->A); - if (r->Ai != NULL) - BN_free(r->Ai); - if (r->e != NULL) - BN_free(r->e); - if (r->mod != NULL) - BN_free(r->mod); + BN_free(r->A); + BN_free(r->Ai); + BN_free(r->e); + BN_free(r->mod); OPENSSL_free(r); } @@ -331,8 +326,7 @@ BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b, goto err; if (e != NULL) { - if (ret->e != NULL) - BN_free(ret->e); + BN_free(ret->e); ret->e = BN_dup(e); } if (ret->e == NULL) @@ -374,7 +368,7 @@ BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b, return ret; err: - if (b == NULL && ret != NULL) { + if (b == NULL) { BN_BLINDING_free(ret); ret = NULL; } diff --git a/crypto/bn/bn_depr.c b/crypto/bn/bn_depr.c index 34895f5982..bc15f8317e 100644 --- a/crypto/bn/bn_depr.c +++ b/crypto/bn/bn_depr.c @@ -73,7 +73,6 @@ BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, { BN_GENCB cb; BIGNUM *rnd = NULL; - int found = 0; BN_GENCB_set_old(&cb, callback, cb_arg); @@ -86,11 +85,10 @@ BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, goto err; /* we have a prime :-) */ - found = 1; + return ret; err: - if (!found && (ret == NULL) && (rnd != NULL)) - BN_free(rnd); - return (found ? rnd : NULL); + BN_free(rnd); + return NULL; } int BN_is_prime(const BIGNUM *a, int checks, diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c index 153a970d05..28c36931a9 100644 --- a/crypto/bn/bn_exp.c +++ b/crypto/bn/bn_exp.c @@ -564,7 +564,7 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, goto err; ret = 1; err: - if ((in_mont == NULL) && (mont != NULL)) + if (in_mont == NULL) BN_MONT_CTX_free(mont); BN_CTX_end(ctx); bn_check_top(rr); @@ -1127,7 +1127,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, goto err; ret = 1; err: - if ((in_mont == NULL) && (mont != NULL)) + if (in_mont == NULL) BN_MONT_CTX_free(mont); if (powerbuf != NULL) { OPENSSL_cleanse(powerbuf, powerbufLen); @@ -1277,7 +1277,7 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, } ret = 1; err: - if ((in_mont == NULL) && (mont != NULL)) + if (in_mont == NULL) BN_MONT_CTX_free(mont); BN_CTX_end(ctx); bn_check_top(rr); diff --git a/crypto/bn/bn_exp2.c b/crypto/bn/bn_exp2.c index 43fd2044c0..e36c23bc33 100644 --- a/crypto/bn/bn_exp2.c +++ b/crypto/bn/bn_exp2.c @@ -295,7 +295,7 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1, goto err; ret = 1; err: - if ((in_mont == NULL) && (mont != NULL)) + if (in_mont == NULL) BN_MONT_CTX_free(mont); BN_CTX_end(ctx); bn_check_top(rr); diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c index 9cffba8b47..2c5e2b26f8 100644 --- a/crypto/bn/bn_lib.c +++ b/crypto/bn/bn_lib.c @@ -541,8 +541,7 @@ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret) i = ((n - 1) / BN_BYTES) + 1; m = ((n - 1) % (BN_BYTES)); if (bn_wexpand(ret, (int)i) == NULL) { - if (bn) - BN_free(bn); + BN_free(bn); return NULL; } ret->top = i; diff --git a/crypto/bn/bn_mod.c b/crypto/bn/bn_mod.c index e0ed47816a..e4763ff2c6 100644 --- a/crypto/bn/bn_mod.c +++ b/crypto/bn/bn_mod.c @@ -254,8 +254,7 @@ int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m)); bn_check_top(r); - if (abs_m) - BN_free(abs_m); + BN_free(abs_m); return ret; } diff --git a/crypto/bn/bn_prime.c b/crypto/bn/bn_prime.c index 2a7822ef1d..ebfcd97e6c 100644 --- a/crypto/bn/bn_prime.c +++ b/crypto/bn/bn_prime.c @@ -285,10 +285,9 @@ int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, /* we have a prime :-) */ found = 1; err: - if (ctx != NULL) { + if (ctx != NULL) BN_CTX_end(ctx); - BN_CTX_free(ctx); - } + BN_CTX_free(ctx); bn_check_top(ret); return found; } @@ -397,8 +396,7 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, if (ctx_passed == NULL) BN_CTX_free(ctx); } - if (mont != NULL) - BN_MONT_CTX_free(mont); + BN_MONT_CTX_free(mont); return (ret); } diff --git a/crypto/bn/bn_print.c b/crypto/bn/bn_print.c index 9b03240e6d..8b59e78916 100644 --- a/crypto/bn/bn_print.c +++ b/crypto/bn/bn_print.c @@ -158,8 +158,7 @@ char *BN_bn2dec(const BIGNUM *a) err: if (bn_data != NULL) OPENSSL_free(bn_data); - if (t != NULL) - BN_free(t); + BN_free(t); if (!ok && buf) { OPENSSL_free(buf); buf = NULL; diff --git a/crypto/bn/bn_sqrt.c b/crypto/bn/bn_sqrt.c index 232af99a21..ab691b79aa 100644 --- a/crypto/bn/bn_sqrt.c +++ b/crypto/bn/bn_sqrt.c @@ -398,9 +398,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) end: if (err) { - if (ret != NULL && ret != in) { + if (ret != in) BN_clear_free(ret); - } ret = NULL; } BN_CTX_end(ctx); diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index f3abe0774f..6a4223c167 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -463,8 +463,7 @@ static int int_dh_bn_cpy(BIGNUM **dst, const BIGNUM *src) return 0; } else a = NULL; - if (*dst) - BN_free(*dst); + BN_free(*dst); *dst = a; return 1; } diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c index 7a8e063fc8..b8b3890d9e 100644 --- a/crypto/dh/dh_check.c +++ b/crypto/dh/dh_check.c @@ -159,7 +159,6 @@ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret) ok = 1; err: - if (q != NULL) - BN_free(q); + BN_free(q); return (ok); } diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 9e2c8b26e6..e2f48b142d 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -172,12 +172,10 @@ static int generate_key(DH *dh) prk = priv_key; if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) { - if (local_prk) - BN_free(local_prk); + BN_free(local_prk); goto err; } - if (local_prk) - BN_free(local_prk); + BN_free(local_prk); } dh->pub_key = pub_key; @@ -187,9 +185,9 @@ static int generate_key(DH *dh) if (ok != 1) DHerr(DH_F_GENERATE_KEY, ERR_R_BN_LIB); - if ((pub_key != NULL) && (dh->pub_key == NULL)) + if (pub_key != dh->pub_key) BN_free(pub_key); - if ((priv_key != NULL) && (dh->priv_key == NULL)) + if (priv_key != dh->priv_key) BN_free(priv_key); BN_CTX_free(ctx); return (ok); @@ -273,7 +271,6 @@ static int dh_init(DH *dh) static int dh_finish(DH *dh) { - if (dh->method_mont_p) - |