From 75ebbd9aa411c5b8b19ded6ace2b34181566b56a Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Wed, 6 May 2015 13:43:59 -0400 Subject: [PATCH] Use p==NULL not !p (in if statements, mainly) Reviewed-by: Tim Hudson --- apps/apps.c | 5 +- apps/ca.c | 2 +- apps/cms.c | 22 ++-- apps/crl.c | 2 +- apps/crl2p7.c | 3 +- apps/pkcs12.c | 18 ++-- apps/pkcs8.c | 10 +- apps/req.c | 2 +- apps/s_client.c | 3 +- apps/smime.c | 12 +-- apps/srp.c | 27 +++-- apps/ts.c | 82 +++++++------- apps/verify.c | 2 +- apps/x509.c | 4 +- crypto/asn1/a_mbstr.c | 2 +- crypto/asn1/a_time.c | 4 +- crypto/asn1/asn1_gen.c | 29 ++--- crypto/asn1/asn_mime.c | 29 ++--- crypto/asn1/asn_moid.c | 3 +- crypto/asn1/asn_mstbl.c | 3 +- crypto/asn1/asn_pack.c | 8 +- crypto/asn1/p5_pbev2.c | 17 ++- crypto/asn1/x_x509a.c | 25 +++-- crypto/bio/bf_nbio.c | 2 +- crypto/bio/bss_conn.c | 2 +- crypto/bio/bss_dgram.c | 2 +- crypto/bio/bss_mem.c | 4 +- crypto/cms/cms_smime.c | 3 +- crypto/conf/conf_def.c | 2 +- crypto/conf/conf_lib.c | 8 +- crypto/dh/dh_ameth.c | 21 ++-- crypto/dsa/dsa_ameth.c | 28 ++--- crypto/ec/ec_ameth.c | 8 +- crypto/ec/ec_asn1.c | 2 +- crypto/ec/ec_curve.c | 12 +-- crypto/ec/ec_mult.c | 5 +- crypto/ec/ec_pmeth.c | 2 +- crypto/evp/evp_cnf.c | 3 +- crypto/evp/evp_pbe.c | 5 +- crypto/evp/evp_pkey.c | 4 +- crypto/evp/pmeth_lib.c | 2 +- crypto/objects/obj_dat.c | 10 +- crypto/ocsp/ocsp_cl.c | 7 +- crypto/ocsp/ocsp_ext.c | 27 ++--- crypto/ocsp/ocsp_lib.c | 6 +- crypto/ocsp/ocsp_prn.c | 2 +- crypto/ocsp/ocsp_srv.c | 22 ++-- crypto/ocsp/ocsp_vfy.c | 3 +- crypto/pem/pem_pk8.c | 9 +- crypto/pem/pvkfmt.c | 5 +- crypto/pkcs12/p12_add.c | 18 ++-- crypto/pkcs12/p12_attr.c | 3 +- crypto/pkcs12/p12_crt.c | 4 +- crypto/pkcs12/p12_decr.c | 6 +- crypto/pkcs12/p12_init.c | 5 +- crypto/pkcs12/p12_kiss.c | 8 +- crypto/pkcs12/p12_mutl.c | 11 +- crypto/pkcs12/p12_npas.c | 14 +-- crypto/pkcs12/p12_p8e.c | 4 +- crypto/pkcs12/p12_utl.c | 6 +- crypto/pkcs7/pk7_attr.c | 13 +-- crypto/pkcs7/pk7_doit.c | 7 +- crypto/pkcs7/pk7_lib.c | 6 +- crypto/pkcs7/pk7_smime.c | 22 ++-- crypto/rsa/rsa_ameth.c | 6 +- crypto/rsa/rsa_pmeth.c | 4 +- crypto/srp/srp_lib.c | 13 ++- crypto/srp/srp_vfy.c | 19 ++-- crypto/ts/ts_conf.c | 61 ++++++----- crypto/ts/ts_rsp_sign.c | 107 ++++++++++--------- crypto/ts/ts_rsp_verify.c | 19 ++-- crypto/ts/ts_verify_ctx.c | 10 +- crypto/txt_db/txt_db.c | 2 +- crypto/x509/x509_att.c | 4 +- crypto/x509/x509_trs.c | 7 +- crypto/x509/x509spki.c | 2 +- crypto/x509v3/pcy_tree.c | 2 +- crypto/x509v3/v3_akey.c | 6 +- crypto/x509v3/v3_alt.c | 38 ++++--- crypto/x509v3/v3_bcons.c | 3 +- crypto/x509v3/v3_bitst.c | 2 +- crypto/x509v3/v3_conf.c | 25 +++-- crypto/x509v3/v3_cpols.c | 32 +++--- crypto/x509v3/v3_crld.c | 11 +- crypto/x509v3/v3_extku.c | 4 +- crypto/x509v3/v3_ia5.c | 5 +- crypto/x509v3/v3_info.c | 7 +- crypto/x509v3/v3_lib.c | 15 +-- crypto/x509v3/v3_pci.c | 2 +- crypto/x509v3/v3_pcons.c | 3 +- crypto/x509v3/v3_pmaps.c | 2 +- crypto/x509v3/v3_prn.c | 9 +- crypto/x509v3/v3_purp.c | 5 +- crypto/x509v3/v3_skey.c | 6 +- crypto/x509v3/v3_sxnet.c | 28 +++-- crypto/x509v3/v3_utl.c | 32 +++--- crypto/x509v3/v3prin.c | 5 +- demos/engines/cluster_labs/hw_cluster_labs.c | 29 +++-- demos/engines/ibmca/hw_ibmca.c | 10 +- demos/engines/zencod/hw_zencod.c | 70 +++++------- demos/pkcs12/pkread.c | 4 +- demos/pkcs12/pkwrite.c | 4 +- engines/ccgost/gost2001.c | 2 +- engines/ccgost/gost_ameth.c | 2 +- engines/e_4758cca.c | 25 ++--- engines/e_aep.c | 18 ++-- engines/e_atalla.c | 11 +- engines/e_capi.c | 6 +- engines/e_chil.c | 29 ++--- engines/e_cswift.c | 14 ++- engines/e_sureware.c | 6 +- engines/e_ubsec.c | 40 +++---- ssl/d1_srtp.c | 2 +- ssl/kssl.c | 6 +- ssl/s3_clnt.c | 18 ++-- ssl/s3_srvr.c | 2 +- ssl/tls_srp.c | 23 ++-- test/ectest.c | 14 +-- 118 files changed, 754 insertions(+), 724 deletions(-) diff --git a/apps/apps.c b/apps/apps.c index 1c182bafb6..ab6eb40579 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -502,11 +502,12 @@ int add_oid_section(CONF *conf) STACK_OF(CONF_VALUE) *sktmp; CONF_VALUE *cnf; int i; - if (!(p = NCONF_get_string(conf, NULL, "oid_section"))) { + + if ((p = NCONF_get_string(conf, NULL, "oid_section")) == NULL) { ERR_clear_error(); return 1; } - if (!(sktmp = NCONF_get_section(conf, p))) { + if ((sktmp = NCONF_get_section(conf, p)) == NULL) { BIO_printf(bio_err, "problem loading oid section %s\n", p); return 0; } diff --git a/apps/ca.c b/apps/ca.c index d7a9aca07d..58f1243cdf 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -1703,7 +1703,7 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, * Its best to dup the subject DN and then delete any email addresses * because this retains its structure. */ - if (!(dn_subject = X509_NAME_dup(subject))) { + if ((dn_subject = X509_NAME_dup(subject)) == NULL) { BIO_printf(bio_err, "Memory allocation failure\n"); goto end; } diff --git a/apps/cms.c b/apps/cms.c index 5eb5d2df6f..5293fbdc6d 100644 --- a/apps/cms.c +++ b/apps/cms.c @@ -717,8 +717,8 @@ int cms_main(int argc, char **argv) if ((encerts = sk_X509_new_null()) == NULL) goto end; while (*argv) { - if (!(cert = load_cert(*argv, FORMAT_PEM, - NULL, e, "recipient certificate file"))) + if ((cert = load_cert(*argv, FORMAT_PEM, NULL, e, + "recipient certificate file")) == NULL) goto end; sk_X509_push(encerts, cert); cert = NULL; @@ -727,24 +727,24 @@ int cms_main(int argc, char **argv) } if (certfile) { - if (!(other = load_certs(certfile, FORMAT_PEM, NULL, - e, "certificate file"))) { + if ((other = load_certs(certfile, FORMAT_PEM, NULL, e, + "certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; } } if (recipfile && (operation == SMIME_DECRYPT)) { - if (!(recip = load_cert(recipfile, FORMAT_PEM, NULL, - e, "recipient certificate file"))) { + if ((recip = load_cert(recipfile, FORMAT_PEM, NULL, e, + "recipient certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; } } if (operation == SMIME_SIGN_RECEIPT) { - if (!(signer = load_cert(signerfile, FORMAT_PEM, NULL, - e, "receipt signer certificate file"))) { + if ((signer = load_cert(signerfile, FORMAT_PEM, NULL, e, + "receipt signer certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; } @@ -787,7 +787,7 @@ int cms_main(int argc, char **argv) } if (contfile) { BIO_free(indata); - if (!(indata = BIO_new_file(contfile, "rb"))) { + if ((indata = BIO_new_file(contfile, "rb")) == NULL) { BIO_printf(bio_err, "Can't read content file %s\n", contfile); goto end; } @@ -807,7 +807,7 @@ int cms_main(int argc, char **argv) if (rctfile) { char *rctmode = (rctformat == FORMAT_ASN1) ? "rb" : "r"; - if (!(rctin = BIO_new_file(rctfile, rctmode))) { + if ((rctin = BIO_new_file(rctfile, rctmode)) == NULL) { BIO_printf(bio_err, "Can't open receipt file %s\n", rctfile); goto end; } @@ -834,7 +834,7 @@ int cms_main(int argc, char **argv) goto end; if ((operation == SMIME_VERIFY) || (operation == SMIME_VERIFY_RECEIPT)) { - if (!(store = setup_verify(CAfile, CApath))) + if ((store = setup_verify(CAfile, CApath)) == NULL) goto end; X509_STORE_set_verify_cb(store, cms_cb); if (vpmtouched) diff --git a/apps/crl.c b/apps/crl.c index b8c592c6e2..443889a753 100644 --- a/apps/crl.c +++ b/apps/crl.c @@ -222,7 +222,7 @@ int crl_main(int argc, char **argv) goto end; if (do_ver) { - if (!(store = setup_verify(CAfile, CApath))) + if ((store = setup_verify(CAfile, CApath)) == NULL) goto end; lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (lookup == NULL) diff --git a/apps/crl2p7.c b/apps/crl2p7.c index fb2b085ead..f05ad4ae52 100644 --- a/apps/crl2p7.c +++ b/apps/crl2p7.c @@ -135,7 +135,8 @@ int crl2pkcs7_main(int argc, char **argv) nocrl = 1; break; case OPT_CERTFILE: - if (!certflst && !(certflst = sk_OPENSSL_STRING_new_null())) + if ((certflst == NULL) + && (certflst = sk_OPENSSL_STRING_new_null()) == NULL) goto end; if (!sk_OPENSSL_STRING_push(certflst, *(++argv))) { sk_OPENSSL_STRING_free(certflst); diff --git a/apps/pkcs12.c b/apps/pkcs12.c index 67d33a21ff..367ba87754 100644 --- a/apps/pkcs12.c +++ b/apps/pkcs12.c @@ -421,8 +421,8 @@ int pkcs12_main(int argc, char **argv) /* Add any more certificates asked for */ if (certfile) { STACK_OF(X509) *morecerts = NULL; - if (!(morecerts = load_certs(certfile, FORMAT_PEM, NULL, e, - "certificates from certfile"))) + if ((morecerts = load_certs(certfile, FORMAT_PEM, NULL, e, + "certificates from certfile")) == NULL) goto export_end; while (sk_X509_num(morecerts) > 0) sk_X509_push(certs, sk_X509_shift(morecerts)); @@ -434,7 +434,7 @@ int pkcs12_main(int argc, char **argv) int vret; STACK_OF(X509) *chain2; X509_STORE *store; - if (!(store = setup_verify(CAfile, CApath))) + if ((store = setup_verify(CAfile, CApath)) == NULL) goto export_end; vret = get_cert_chain(ucert, store, &chain2); @@ -511,7 +511,7 @@ int pkcs12_main(int argc, char **argv) } - if (!(p12 = d2i_PKCS12_bio(in, NULL))) { + if ((p12 = d2i_PKCS12_bio(in, NULL)) == NULL) { ERR_print_errors(bio_err); goto end; } @@ -570,7 +570,7 @@ int dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass, int ret = 0; PKCS7 *p7; - if (!(asafes = PKCS12_unpack_authsafes(p12))) + if ((asafes = PKCS12_unpack_authsafes(p12)) == NULL) return 0; for (i = 0; i < sk_PKCS7_num(asafes); i++) { p7 = sk_PKCS7_value(asafes, i); @@ -634,7 +634,7 @@ int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass, return 1; print_attribs(out, bag->attrib, "Bag Attributes"); p8 = bag->value.keybag; - if (!(pkey = EVP_PKCS82PKEY(p8))) + if ((pkey = EVP_PKCS82PKEY(p8)) == NULL) return 0; print_attribs(out, p8->attributes, "Key Attributes"); PEM_write_bio_PrivateKey(out, pkey, enc, NULL, 0, NULL, pempass); @@ -649,9 +649,9 @@ int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass, if (options & NOKEYS) return 1; print_attribs(out, bag->attrib, "Bag Attributes"); - if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen))) + if ((p8 = PKCS12_decrypt_skey(bag, pass, passlen)) == NULL) return 0; - if (!(pkey = EVP_PKCS82PKEY(p8))) { + if ((pkey = EVP_PKCS82PKEY(p8)) == NULL) { PKCS8_PRIV_KEY_INFO_free(p8); return 0; } @@ -674,7 +674,7 @@ int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass, print_attribs(out, bag->attrib, "Bag Attributes"); if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate) return 1; - if (!(x509 = PKCS12_certbag2x509(bag))) + if ((x509 = PKCS12_certbag2x509(bag)) == NULL) return 0; dump_cert_text(out, x509); PEM_write_bio_X509(out, x509); diff --git a/apps/pkcs8.c b/apps/pkcs8.c index 07ebf3b86f..55c4eea0aa 100644 --- a/apps/pkcs8.c +++ b/apps/pkcs8.c @@ -211,7 +211,7 @@ int pkcs8_main(int argc, char **argv) pkey = load_key(infile, informat, 1, passin, e, "key"); if (!pkey) goto end; - if (!(p8inf = EVP_PKEY2PKCS8_broken(pkey, p8_broken))) { + if ((p8inf = EVP_PKEY2PKCS8_broken(pkey, p8_broken)) == NULL) { BIO_printf(bio_err, "Error converting key\n"); ERR_print_errors(bio_err); goto end; @@ -235,9 +235,9 @@ int pkcs8_main(int argc, char **argv) goto end; } app_RAND_load_file(NULL, 0); - if (!(p8 = PKCS8_encrypt(pbe_nid, cipher, - p8pass, strlen(p8pass), - NULL, 0, iter, p8inf))) { + if ((p8 = PKCS8_encrypt(pbe_nid, cipher, + p8pass, strlen(p8pass), + NULL, 0, iter, p8inf)) == NULL) { BIO_printf(bio_err, "Error encrypting key\n"); ERR_print_errors(bio_err); goto end; @@ -296,7 +296,7 @@ int pkcs8_main(int argc, char **argv) goto end; } - if (!(pkey = EVP_PKCS82PKEY(p8inf))) { + if ((pkey = EVP_PKCS82PKEY(p8inf)) == NULL) { BIO_printf(bio_err, "Error converting key\n"); ERR_print_errors(bio_err); goto end; diff --git a/apps/req.c b/apps/req.c index 225474b4f5..8acdad350d 100644 --- a/apps/req.c +++ b/apps/req.c @@ -962,7 +962,7 @@ static int build_subject(X509_REQ *req, char *subject, unsigned long chtype, { X509_NAME *n; - if (!(n = parse_name(subject, chtype, multirdn))) + if ((n = parse_name(subject, chtype, multirdn)) == NULL) return 0; if (!X509_REQ_set_subject_name(req, n)) { diff --git a/apps/s_client.c b/apps/s_client.c index a24d2f3b9d..b257727edb 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -345,7 +345,8 @@ static int ssl_srp_verify_param_cb(SSL *s, void *arg) { SRP_ARG *srp_arg = (SRP_ARG *)arg; BIGNUM *N = NULL, *g = NULL; - if (!(N = SSL_get_srp_N(s)) || !(g = SSL_get_srp_g(s))) + + if (((N = SSL_get_srp_N(s)) == NULL) || ((g = SSL_get_srp_g(s)) == NULL)) return 0; if (srp_arg->debug || srp_arg->msg || srp_arg->amp == 1) { BIO_printf(bio_err, "SRP parameters:\n"); diff --git a/apps/smime.c b/apps/smime.c index e544ca2161..3f48278cd1 100644 --- a/apps/smime.c +++ b/apps/smime.c @@ -463,16 +463,16 @@ int smime_main(int argc, char **argv) } if (certfile) { - if (!(other = load_certs(certfile, FORMAT_PEM, NULL, - e, "certificate file"))) { + if ((other = load_certs(certfile, FORMAT_PEM, NULL, + e, "certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; } } if (recipfile && (operation == SMIME_DECRYPT)) { - if (!(recip = load_cert(recipfile, FORMAT_PEM, NULL, - e, "recipient certificate file"))) { + if ((recip = load_cert(recipfile, FORMAT_PEM, NULL, + e, "recipient certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; } @@ -515,7 +515,7 @@ int smime_main(int argc, char **argv) } if (contfile) { BIO_free(indata); - if (!(indata = BIO_new_file(contfile, "rb"))) { + if ((indata = BIO_new_file(contfile, "rb")) == NULL) { BIO_printf(bio_err, "Can't read content file %s\n", contfile); goto end; } @@ -527,7 +527,7 @@ int smime_main(int argc, char **argv) goto end; if (operation == SMIME_VERIFY) { - if (!(store = setup_verify(CAfile, CApath))) + if ((store = setup_verify(CAfile, CApath)) == NULL) goto end; X509_STORE_set_verify_cb(store, smime_cb); if (vpmtouched) diff --git a/apps/srp.c b/apps/srp.c index 111f829ca6..ec875cb9fb 100644 --- a/apps/srp.c +++ b/apps/srp.c @@ -516,10 +516,13 @@ int srp_main(int argc, char **argv) row[DB_srptype] = BUF_strdup("v"); row[DB_srpgN] = BUF_strdup(gNid); - if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype] - || !row[DB_srpverifier] || !row[DB_srpsalt] - || (userinfo && - (!(row [DB_srpinfo] = BUF_strdup (userinfo)))) + if ((row[DB_srpid] == NULL) + || (row[DB_srpgN] == NULL) + || (row[DB_srptype] == NULL) + || (row[DB_srpverifier] == NULL) + || (row[DB_srpsalt] == NULL) + || (userinfo + && ((row[DB_srpinfo] = BUF_strdup(userinfo)) == NULL)) || !update_index(db, row)) { OPENSSL_free(row[DB_srpid]); OPENSSL_free(row[DB_srpgN]); @@ -596,10 +599,14 @@ int srp_main(int argc, char **argv) row[DB_srptype][0] = 'v'; row[DB_srpgN] = BUF_strdup(gNid); - if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype] - || !row[DB_srpverifier] || !row[DB_srpsalt] + if (row[DB_srpid] == NULL + || row[DB_srpgN] == NULL + || row[DB_srptype] == NULL + || row[DB_srpverifier] == NULL + || row[DB_srpsalt] == NULL || (userinfo - && (!(row[DB_srpinfo] = BUF_strdup(userinfo))))) + && ((row[DB_srpinfo] = BUF_strdup(userinfo)) + == NULL))) goto end; doupdatedb = 1; @@ -612,12 +619,10 @@ int srp_main(int argc, char **argv) user); errors++; } else { - char **xpp = - sk_OPENSSL_PSTRING_value(db->db->data, userindex); - BIO_printf(bio_err, "user \"%s\" revoked. t\n", user); + char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex); + BIO_printf(bio_err, "user \"%s\" revoked. t\n", user); xpp[DB_srptype][0] = 'R'; - doupdatedb = 1; } } diff --git a/apps/ts.c b/apps/ts.c index 3cfdc79e4e..5c42ff5e38 100644 --- a/apps/ts.c +++ b/apps/ts.c @@ -381,7 +381,7 @@ static ASN1_OBJECT *txt2obj(const char *oid) { ASN1_OBJECT *oid_obj = NULL; - if (!(oid_obj = OBJ_txt2obj(oid, 0))) + if ((oid_obj = OBJ_txt2obj(oid, 0)) == NULL) BIO_printf(bio_err, "cannot convert %s to OID\n", oid); return oid_obj; @@ -398,8 +398,8 @@ static CONF *load_config_file(const char *configfile) configfile = getenv("SSLEAY_CONF"); if (configfile && - (!(conf = NCONF_new(NULL)) || - NCONF_load(conf, configfile, &errorline) <= 0)) { + ((conf = NCONF_new(NULL)) == NULL + || NCONF_load(conf, configfile, &errorline) <= 0)) { if (errorline <= 0) BIO_printf(bio_err, "error loading the config file " "'%s'\n", configfile); @@ -449,7 +449,8 @@ static int query_command(const char *data, char *digest, const EVP_MD *md, query = d2i_TS_REQ_bio(in_bio, NULL); } else { /* Open the file if no explicit digest bytes were specified. */ - if (!digest && !(data_bio = bio_open_default(data, "rb"))) + if (digest == NULL + && (data_bio = bio_open_default(data, "rb")) == NULL) goto end; query = create_query(data_bio, digest, md, policy, no_nonce, cert); } @@ -496,11 +497,11 @@ static TS_REQ *create_query(BIO *data_bio, char *digest, const EVP_MD *md, ASN1_INTEGER *nonce_asn1 = NULL; /* Setting default message digest. */ - if (!md && !(md = EVP_get_digestbyname("sha1"))) + if (md == NULL && (md = EVP_get_digestbyname("sha1")) == NULL) goto err; /* Creating request object. */ - if (!(ts_req = TS_REQ_new())) + if ((ts_req = TS_REQ_new()) == NULL) goto err; /* Setting version. */ @@ -508,15 +509,15 @@ static TS_REQ *create_query(BIO *data_bio, char *digest, const EVP_MD *md, goto err; /* Creating and adding MSG_IMPRINT object. */ - if (!(msg_imprint = TS_MSG_IMPRINT_new())) + if ((msg_imprint = TS_MSG_IMPRINT_new()) == NULL) goto err; /* Adding algorithm. */ - if (!(algo = X509_ALGOR_new())) + if ((algo = X509_ALGOR_new()) == NULL) goto err; - if (!(algo->algorithm = OBJ_nid2obj(EVP_MD_type(md)))) + if ((algo->algorithm = OBJ_nid2obj(EVP_MD_type(md))) == NULL) goto err; - if (!(algo->parameter = ASN1_TYPE_new())) + if ((algo->parameter = ASN1_TYPE_new()) == NULL) goto err; algo->parameter->type = V_ASN1_NULL; if (!TS_MSG_IMPRINT_set_algo(msg_imprint, algo)) @@ -532,13 +533,13 @@ static TS_REQ *create_query(BIO *data_bio, char *digest, const EVP_MD *md, goto err; /* Setting policy if requested. */ - if (policy && !(policy_obj = txt2obj(policy))) + if (policy && (policy_obj = txt2obj(policy)) == NULL) goto err; if (policy_obj && !TS_REQ_set_policy_id(ts_req, policy_obj)) goto err; /* Setting nonce if requested. */ - if (!no_nonce && !(nonce_asn1 = create_nonce(NONCE_LENGTH))) + if (!no_nonce && (nonce_asn1 = create_nonce(NONCE_LENGTH)) == NULL) goto err; if (nonce_asn1 && !TS_REQ_set_nonce(ts_req, nonce_asn1)) goto err; @@ -615,8 +616,9 @@ static ASN1_INTEGER *create_nonce(int bits) goto err; /* Find the first non-zero byte and creating ASN1_INTEGER object. */ - for (i = 0; i < len && !buf[i]; ++i) ; - if (!(nonce = ASN1_INTEGER_new())) + for (i = 0; i < len && !buf[i]; ++i) + continue; + if ((nonce = ASN1_INTEGER_new()) == NULL) goto err; OPENSSL_free(nonce->data); /* Allocate at least one byte. */ @@ -725,17 +727,17 @@ static TS_RESP *read_PKCS7(BIO *in_bio) TS_STATUS_INFO *si = NULL; /* Read PKCS7 object and extract the signed time stamp info. */ - if (!(token = d2i_PKCS7_bio(in_bio, NULL))) + if ((token = d2i_PKCS7_bio(in_bio, NULL)) == NULL) goto end; - if (!(tst_info = PKCS7_to_TS_TST_INFO(token))) + if ((tst_info = PKCS7_to_TS_TST_INFO(token)) == NULL) goto end; /* Creating response object. */ - if (!(resp = TS_RESP_new())) + if ((resp = TS_RESP_new()) == NULL) goto end; /* Create granted status info. */ - if (!(si = TS_STATUS_INFO_new())) + if ((si = TS_STATUS_INFO_new()) == NULL) goto end; if (!(ASN1_INTEGER_set(si->status, TS_STATUS_GRANTED))) goto end; @@ -769,15 +771,15 @@ static TS_RESP *create_response(CONF *conf, const char *section, char *engine, BIO *query_bio = NULL; TS_RESP_CTX *resp_ctx = NULL; - if (!(query_bio = BIO_new_file(queryfile, "rb"))) + if ((query_bio = BIO_new_file(queryfile, "rb")) == NULL) goto end; /* Getting TSA configuration section. */ - if (!(section = TS_CONF_get_tsa_section(conf, section))) + if ((section = TS_CONF_get_tsa_section(conf, section)) == NULL) goto end; /* Setting up response generation context. */ - if (!(resp_ctx = TS_RESP_CTX_new())) + if ((resp_ctx = TS_RESP_CTX_new()) == NULL) goto end; /* Setting serial number provider callback. */ @@ -834,7 +836,7 @@ static TS_RESP *create_response(CONF *conf, const char *section, char *engine, goto end; /* Creating the response. */ - if (!(response = TS_RESP_create_response(resp_ctx, query_bio))) + if ((response = TS_RESP_create_response(resp_ctx, query_bio)) == NULL) goto end; ret = 1; @@ -872,10 +874,10 @@ static ASN1_INTEGER *next_serial(const char *serialfile) ASN1_INTEGER *serial = NULL; BIGNUM *bn = NULL; - if (!(serial = ASN1_INTEGER_new())) + if ((serial = ASN1_INTEGER_new()) == NULL) goto err; - if (!(in = BIO_new_file(serialfile, "r"))) { + if ((in = BIO_new_file(serialfile, "r")) == NULL) { ERR_clear_error(); BIO_printf(bio_err, "Warning: could not open file %s for " "reading, using serial number: 1\n", serialfile); @@ -888,13 +890,13 @@ static ASN1_INTEGER *next_serial(const char *serialfile) serialfile); goto err; } - if (!(bn = ASN1_INTEGER_to_BN(serial, NULL))) + if ((bn = ASN1_INTEGER_to_BN(serial, NULL)) == NULL) goto err; ASN1_INTEGER_free(serial); serial = NULL; if (!BN_add_word(bn, 1)) goto err; - if (!(serial = BN_to_ASN1_INTEGER(bn, NULL))) + if ((serial = BN_to_ASN1_INTEGER(bn, NULL)) == NULL) goto err; } ret = 1; @@ -913,7 +915,7 @@ static int save_ts_serial(const char *serialfile, ASN1_INTEGER *serial) int ret = 0; BIO *out = NULL; - if (!(out = BIO_new_file(serialfile, "w"))) + if ((out = BIO_new_file(serialfile, "w")) == NULL) goto err; if (i2a_ASN1_INTEGER(out, serial) <= 0) goto err; @@ -943,18 +945,18 @@ static int verify_command(char *data, char *digest, char *queryfile, int ret = 0; /* Decode the token (PKCS7) or response (TS_RESP) files. */ - if (!(in_bio = BIO_new_file(in, "rb"))) + if ((in_bio = BIO_new_file(in, "rb")) == NULL) goto end; if (token_in) { - if (!(token = d2i_PKCS7_bio(in_bio, NULL))) + if ((token = d2i_PKCS7_bio(in_bio, NULL)) == NULL) goto end; } else { - if (!(response = d2i_TS_RESP_bio(in_bio, NULL))) + if ((response = d2i_TS_RESP_bio(in_bio, NULL)) == NULL) goto end; } - if (!(verify_ctx = create_verify_ctx(data, digest, queryfile, - CApath, CAfile, untrusted))) + if ((verify_ctx = create_verify_ctx(data, digest, queryfile, + CApath, CAfile, untrusted)) == NULL) goto end; /* Checking the token or response against the request. */ @@ -991,17 +993,17 @@ static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest, int ret = 0; if (data != NULL || digest != NULL) { - if (!(ctx = TS_VERIFY_CTX_new())) + if ((ctx = TS_VERIFY_CTX_new()) == NULL) goto err; ctx->flags = TS_VFY_VERSION | TS_VFY_SIGNER; if (data != NULL) { ctx->flags |= TS_VFY_DATA; - if (!(ctx->data = BIO_new_file(data, "rb"))) + if ((ctx->data = BIO_new_file(data, "rb")) == NULL) goto err; } else if (digest != NULL) { long imprint_len; ctx->flags |= TS_VFY_IMPRINT; - if (!(ctx->imprint = string_to_hex(digest, &imprint_len))) { + if ((ctx->imprint = string_to_hex(digest, &imprint_len)) == NULL) { BIO_printf(bio_err, "invalid digest string\n"); goto err; } @@ -1013,11 +1015,11 @@ static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest, * The request has just to be read, decoded and converted to a verify * context object. */ - if (!(input = BIO_new_file(queryfile, "rb"))) + if ((input = BIO_new_file(queryfile, "rb")) == NULL) goto err; - if (!(request = d2i_TS_REQ_bio(input, NULL))) + if ((request = d2i_TS_REQ_bio(input, NULL)) == NULL) goto err; - if (!(ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL))) + if ((ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL)) == NULL) goto err; } else return NULL; @@ -1026,11 +1028,11 @@ static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest, ctx->flags |= TS_VFY_SIGNATURE; /* Initialising the X509_STORE object. */ - if (!(ctx->store = create_cert_store(CApath, CAfile))) + if ((ctx->store = create_cert_store(CApath, CAfile)) == NULL) goto err; /* Loading untrusted certificates. */ - if (untrusted && !(ctx->certs = TS_CONF_load_certs(untrusted))) + if (untrusted && (ctx->certs = TS_CONF_load_certs(untrusted)) == NULL) goto err; ret = 1; diff --git a/apps/verify.c b/apps/verify.c index f4e18f0535..cb1be9a765 100644 --- a/apps/verify.c +++ b/apps/verify.c @@ -177,7 +177,7 @@ int verify_main(int argc, char **argv) argc = opt_num_rest(); argv = opt_rest(); - if (!(store = setup_verify(CAfile, CApath))) + if ((store = setup_verify(CAfile, CApath)) == NULL) goto end; X509_STORE_set_verify_cb(store, cb); diff --git a/apps/x509.c b/apps/x509.c index 5938b43412..f22eef18f3 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -1021,11 +1021,9 @@ static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest, } if (sno) bs = sno; - else if (!(bs = x509_load_serial(CAfile, serialfile, create))) + else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL) goto end; -/* if (!X509_STORE_add_cert(ctx,x)) goto end;*/ - /* * NOTE: this certificate can/should be self signed, unless it was a * certificate request in which case it is not. diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c index 2ff496b4fd..ddb2798069 100644 --- a/crypto/asn1/a_mbstr.c +++ b/crypto/asn1/a_mbstr.c @@ -235,7 +235,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, cpyfunc = cpy_utf8; break; } - if (!(p = OPENSSL_malloc(outlen + 1))) { + if ((p = OPENSSL_malloc(outlen + 1)) == NULL) { if (free_out) ASN1_STRING_free(dest); ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE); diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c index 7ff3de37eb..6114c52dc7 100644 --- a/crypto/asn1/a_time.c +++ b/crypto/asn1/a_time.c @@ -116,8 +116,8 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, if (!ASN1_TIME_check(t)) return NULL; - if (!out || !*out) { - if (!(ret = ASN1_GENERALIZEDTIME_new())) + if (out == NULL || *out == NULL) { + if ((ret = ASN1_GENERALIZEDTIME_new()) == NULL) return NULL; if (out) *out = ret; diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c index 84d85e63cd..3ff1db8e0b 100644 --- a/crypto/asn1/asn1_gen.c +++ b/crypto/asn1/asn1_gen.c @@ -492,15 +492,12 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf, if (derlen < 0) goto bad; - - if (!(ret = ASN1_TYPE_new())) + if ((ret = ASN1_TYPE_new()) == NULL) goto bad; - - if (!(ret->value.asn1_string = ASN1_STRING_type_new(utype))) + if ((ret->value.asn1_string = ASN1_STRING_type_new(utype)) == NULL) goto bad; ret->type = utype; - ret->value.asn1_string->data = der; ret->value.asn1_string->length = derlen; @@ -631,15 +628,12 @@ static int asn1_str2tag(const char *tagstr, int len) static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) { ASN1_TYPE *atmp = NULL; - CONF_VALUE vtmp; - unsigned char *rdata; long rdlen; - int no_unused = 1; - if (!(atmp = ASN1_TYPE_new())) { + if ((atmp = ASN1_TYPE_new()) == NULL) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); return NULL; } @@ -676,7 +670,8 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) { + if ((atmp->value.integer + = s2i_ASN1_INTEGER(NULL, (char *)str)) == NULL) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); goto bad_str; } @@ -687,7 +682,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.object = OBJ_txt2obj(str, 0))) { + if ((atmp->value.object = OBJ_txt2obj(str, 0)) == NULL) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); goto bad_str; } @@ -699,7 +694,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.asn1_string = ASN1_STRING_new())) { + if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_str; } @@ -724,7 +719,6 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) case V_ASN1_UNIVERSALSTRING: case V_ASN1_GENERALSTRING: case V_ASN1_NUMERICSTRING: - if (format == ASN1_GEN_FORMAT_ASCII) format = MBSTRING_ASC; else if (format == ASN1_GEN_FORMAT_UTF8) @@ -743,25 +737,20 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) break; case V_ASN1_BIT_STRING: - case V_ASN1_OCTET_STRING: - - if (!(atmp->value.asn1_string = ASN1_STRING_new())) { + if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_form; } if (format == ASN1_GEN_FORMAT_HEX) { - - if (!(rdata = string_to_hex((char *)str, &rdlen))) { + if ((rdata = string_to_hex((char *)str, &rdlen)) == NULL) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); goto bad_str; } - atmp->value.asn1_string->data = rdata; atmp->value.asn1_string->length = rdlen; atmp->value.asn1_string->type = utype; - } else if (format == ASN1_GEN_FORMAT_ASCII) ASN1_STRING_set(atmp->value.asn1_string, str, -1); else if ((format == ASN1_GEN_FORMAT_BITLIST) diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 2fe6cf987e..9ce4013049 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -180,7 +180,8 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it) { BIO *b64; ASN1_VALUE *val; - if (!(b64 = BIO_new(BIO_f_base64()))) { + + if ((b64 = BIO_new(BIO_f_base64())) == NULL) { ASN1err(ASN1_F_B64_READ_ASN1, ERR_R_MALLOC_FAILURE); return 0; } @@ -427,12 +428,13 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) if (bcont) *bcont = NULL; - if (!(headers = mime_parse_hdr(bio))) { + if ((headers = mime_parse_hdr(bio)) == NULL) { ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_PARSE_ERROR); return NULL; } - if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { + if ((hdr = mime_hdr_find(headers, "content-type")) == NULL + || hdr->value == NULL) { sk_MIME_HEADER_pop_free(headers, mime_hdr_free); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE); return NULL; @@ -459,7 +461,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) /* Parse the signature piece */ asnin = sk_BIO_value(parts, 1); - if (!(headers = mime_parse_hdr(asnin))) { + if ((headers = mime_parse_hdr(asnin)) == NULL) { ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_SIG_PARSE_ERROR); sk_BIO_pop_free(parts, BIO_vfree); return NULL; @@ -467,7 +469,8 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) /* Get content type */ - if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { + if ((hdr = mime_hdr_find(headers, "content-type")) == NULL + || hdr->value == NULL) { sk_MIME_HEADER_pop_free(headers, mime_hdr_free); ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE); return NULL; @@ -483,7 +486,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) } sk_MIME_HEADER_pop_free(headers, mime_hdr_free); /* Read in ASN1 */ - if (!(val = b64_read_asn1(asnin, it))) { + if ((val = b64_read_asn1(asnin, it)) == NULL) { ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_SIG_PARSE_ERROR); sk_BIO_pop_free(parts, BIO_vfree); return NULL; @@ -510,7 +513,7 @@ ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it) sk_MIME_HEADER_pop_free(headers, mime_hdr_free); - if (!(val = b64_read_asn1(bio, it))) { + if ((val = b64_read_asn1(bio, it)) == NULL) { ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR); return NULL; } @@ -573,11 +576,12 @@ int SMIME_text(BIO *in, BIO *out) STACK_OF(MIME_HEADER) *headers; MIME_HEADER *hdr; - if (!(headers = mime_parse_hdr(in))) { + if ((headers = mime_parse_hdr(in)) == NULL) { ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_PARSE_ERROR); return 0; } - if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { + if ((hdr = mime_hdr_find(headers, "content-type")) == NULL + || hdr->value == NULL) { ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_NO_CONTENT_TYPE); sk_MIME_HEADER_pop_free(headers, mime_hdr_free); return 0; @@ -822,8 +826,9 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) MIME_HEADER *mhdr = NULL; char *tmpname = NULL, *tmpval = NULL, *p; int c; + if (name) { - if (!(tmpname = BUF_strdup(name))) + if ((tmpname = BUF_strdup(name)) == NULL) return NULL; for (p = tmpname; *p; p++) { c = (unsigned char)*p; @@ -834,7 +839,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) } } if (value) { - if (!(tmpval = BUF_strdup(value))) + if ((tmpval = BUF_strdup(value)) == NULL) goto err; for (p = tmpval; *p; p++) { c = (unsigned char)*p; @@ -849,7 +854,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) goto err; mhdr->name = tmpname; mhdr->value = tmpval; - if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) + if ((mhdr->params = sk_MIME_PARAM_new(mime_param_cmp)) == NULL) goto err; return mhdr; diff --git a/crypto/asn1/asn_moid.c b/crypto/asn1/asn_moid.c index da7e29119a..9459bb249e 100644 --- a/crypto/asn1/asn_moid.c +++ b/crypto/asn1/asn_moid.c @@ -76,8 +76,9 @@ static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) const char *oid_section; STACK_OF(CONF_VALUE) *sktmp; CONF_VALUE *oval; + oid_section = CONF_imodule_get_value(md); - if (!(sktmp = NCONF_get_section(cnf, oid_section))) { + if ((sktmp = NCONF_get_section(cnf, oid_section)) == NULL) { ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); return 0; } diff --git a/crypto/asn1/asn_mstbl.c b/crypto/asn1/asn_mstbl.c index 9b50d14001..a2e80b1fd6 100644 --- a/crypto/asn1/asn_mstbl.c +++ b/crypto/asn1/asn_mstbl.c @@ -70,8 +70,9 @@ static int stbl_module_init(CONF_IMODULE *md, const CONF *cnf) const char *stbl_section; STACK_OF(CONF_VALUE) *sktmp; CONF_VALUE *mval; + stbl_section = CONF_imodule_get_value(md); - if (!(sktmp = NCONF_get_section(cnf, stbl_section))) { + if ((sktmp = NCONF_get_section(cnf, stbl_section)) == NULL) { ASN1err(ASN1_F_STBL_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); return 0; } diff --git a/crypto/asn1/asn_pack.c b/crypto/asn1/asn_pack.c index e358a8676f..b80016ba82 100644 --- a/crypto/asn1/asn_pack.c +++ b/crypto/asn1/asn_pack.c @@ -67,8 +67,8 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) { ASN1_STRING *octmp; - if (!oct || !*oct) { - if (!(octmp = ASN1_STRING_new())) { + if (oct == NULL|| *oct== NULL) { + if ((octmp = ASN1_STRING_new()) == NULL) { ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE); return NULL; } @@ -80,7 +80,7 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) OPENSSL_free(octmp->data); octmp->data = NULL; - if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { + if ((octmp->length = ASN1_item_i2d(obj, &octmp->data, it)) == 0) { ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR); return NULL; } @@ -99,7 +99,7 @@ void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it) void *ret; p = oct->data; - if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) + if ((ret = ASN1_item_d2i(NULL, &p, oct->length, it)) == NULL) ASN1err(ASN1_F_ASN1_ITEM_UNPACK, ASN1_R_DECODE_ERROR); return ret; } diff --git a/crypto/asn1/p5_pbev2.c b/crypto/asn1/p5_pbev2.c index 4b9045e3fb..c7a12402b2 100644 --- a/crypto/asn1/p5_pbev2.c +++ b/crypto/asn1/p5_pbev2.c @@ -106,14 +106,13 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, } obj = OBJ_nid2obj(alg_nid); - if (!(pbe2 = PBE2PARAM_new())) + if ((pbe2 = PBE2PARAM_new()) == NULL) goto merr; /* Setup the AlgorithmIdentifier for the encryption scheme */ scheme = pbe2->encryption; - scheme->algorithm = obj; - if (!(scheme->parameter = ASN1_TYPE_new())) + if ((scheme->parameter = ASN1_TYPE_new()) == NULL) goto merr; /* Create random IV */ @@ -163,7 +162,7 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, /* Now set up top level AlgorithmIdentifier */ - if (!(ret = X509_ALGOR_new())) + if ((ret = X509_ALGOR_new()) == NULL) goto merr; ret->algorithm = OBJ_nid2obj(NID_pbes2); @@ -205,17 +204,17 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, PBKDF2PARAM *kdf = NULL; ASN1_OCTET_STRING *osalt = NULL; - if (!(kdf = PBKDF2PARAM_new())) + if ((kdf = PBKDF2PARAM_new()) == NULL) goto merr; - if (!(osalt = ASN1_OCTET_STRING_new())) + if ((osalt = ASN1_OCTET_STRING_new()) == NULL) goto merr; kdf->salt->value.octet_string = osalt; kdf->salt->type = V_ASN1_OCTET_STRING; - if (!saltlen) + if (saltlen == 0) saltlen = PKCS5_SALT_LEN; - if (!(osalt->data = OPENSSL_malloc(saltlen))) + if ((osalt->data = OPENSSL_malloc(saltlen)) == NULL) goto merr; osalt->length = saltlen; @@ -234,7 +233,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, /* If have a key len set it up */ if (keylen > 0) { - if (!(kdf->keylength = ASN1_INTEGER_new())) + if ((kdf->keylength = ASN1_INTEGER_new()) == NULL) goto merr; if (!ASN1_INTEGER_set(kdf->keylength, keylen)) goto merr; diff --git a/crypto/asn1/x_x509a.c b/crypto/asn1/x_x509a.c index 775e46f516..b0a6b4a70a 100644 --- a/crypto/asn1/x_x509a.c +++ b/crypto/asn1/x_x509a.c @@ -84,9 +84,9 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX) static X509_CERT_AUX *aux_get(X509 *x) { - if (!x) + if (x == NULL) return NULL; - if (!x->aux && !(x->aux = X509_CERT_AUX_new())) + if (x->aux == NULL && (x->aux = X509_CERT_AUX_new()) == NULL) return NULL; return x->aux; } @@ -101,9 +101,9 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len) x->aux->alias = NULL; return 1; } - if (!(aux = aux_get(x))) + if ((aux = aux_get(x)) == NULL) return 0; - if (!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) + if (aux->alias == NULL && (aux->alias = ASN1_UTF8STRING_new()) == NULL) return 0; return ASN1_STRING_set(aux->alias, name, len); } @@ -118,9 +118,10 @@ int X509_keyid_set1(X509 *x, unsigned char *id, int len) x->aux->keyid = NULL; return 1; } - if (!(aux = aux_get(x))) + if ((aux = aux_get(x)) == NULL) return 0; - if (!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) + if (aux->keyid ==NULL + && (aux->keyid = ASN1_OCTET_STRING_new()) == NULL) return 0; return ASN1_STRING_set(aux->keyid, id, len); } @@ -152,9 +153,10 @@ int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj) if (!objtmp) return 0; } - if (!(aux = aux_get(x))) + if ((aux = aux_get(x)) == NULL) goto err; - if (!aux->trust && !(aux->trust = sk_ASN1_OBJECT_new_null())) + if (aux->trust == NULL + && (aux->trust = sk_ASN1_OBJECT_new_null()) == NULL) goto err; if (!objtmp || sk_ASN1_OBJECT_push(aux->trust, objtmp)) return 1; @@ -167,11 +169,12 @@ int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj) { X509_CERT_AUX *aux; ASN1_OBJECT *objtmp; - if (!(objtmp = OBJ_dup(obj))) + if ((objtmp = OBJ_dup(obj)) == NULL) return 0; - if (!(aux = aux_get(x))) + if ((aux = aux_get(x)) == NULL) return 0; - if (!aux->reject && !(aux->reject = sk_ASN1_OBJECT_new_null())) + if (aux->reject == NULL + && (aux->reject = sk_ASN1_OBJECT_new_null()) == NULL) return 0; return sk_ASN1_OBJECT_push(aux->reject, objtmp); } diff --git a/crypto/bio/bf_nbio.c b/crypto/bio/bf_nbio.c index 53829ddac7..dc98c4fd5d 100644 --- a/crypto/bio/bf_nbio.c +++ b/crypto/bio/bf_nbio.c @@ -102,7 +102,7 @@ static int nbiof_new(BIO *bi) { NBIO_TEST *nt; - if (!(nt = OPENSSL_malloc(sizeof(*nt)))) + if ((nt = OPENSSL_malloc(sizeof(*nt))) == NULL) return (0); nt->lrn = -1; nt->lwn = -1; diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c index 60f58e2d22..9b2cee44cf 100644 --- a/crypto/bio/bss_conn.c +++ b/crypto/bio/bss_conn.c @@ -269,7 +269,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c) } if (cb != NULL) { - if (!(ret = cb((BIO *)b, c->state, ret))) + if ((ret = cb((BIO *)b, c->state, ret)) == 0) goto end; } } diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c index 53d8136d64..268481c9ab 100644 --- a/crypto/bio/bss_dgram.c +++ b/crypto/bio/bss_dgram.c @@ -1406,7 +1406,7 @@ static int dgram_sctp_write(BIO *b, const char *in, int inl) if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) { char *tmp; data->saved_message.bio = b; - if (!(tmp = OPENSSL_malloc(inl))) { + if ((tmp = OPENSSL_malloc(inl)) == NULL) { BIOerr(BIO_F_DGRAM_SCTP_WRITE, ERR_R_MALLOC_FAILURE); return -1; } diff --git a/crypto/bio/bss_mem.c b/crypto/bio/bss_mem.c index 56e0d2e323..c55344d320 100644 --- a/crypto/bio/bss_mem.c +++ b/crypto/bio/bss_mem.c @@ -97,12 +97,12 @@ BIO *BIO_new_mem_buf(void *buf, int len) BUF_MEM *b; size_t sz; - if (!buf) { + if (buf == NULL) { BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER); return NULL; } sz = (len < 0) ? strlen(buf) : (size_t)len; - if (!(ret = BIO_new(BIO_s_mem()))) + if ((ret = BIO_new(BIO_s_mem())) == NULL) return NULL; b = (BUF_MEM *)ret->ptr; b->data = buf; diff --git a/crypto/cms/cms_smime.c b/crypto/cms/cms_smime.c index d19ec6d02c..c161973d29 100644 --- a/crypto/cms/cms_smime.c +++ b/crypto/cms/cms_smime.c @@ -801,7 +801,8 @@ int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags) { BIO *cmsbio; int ret = 0; - if (!(cmsbio = CMS_dataInit(cms, dcont))) { + + if ((cmsbio = CMS_dataInit(cms, dcont)) == NULL) { CMSerr(CMS_F_CMS_FINAL, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c index 8af2ab13ab..ee71f48200 100644 --- a/crypto/conf/conf_def.c +++ b/crypto/conf/conf_def.c @@ -357,7 +357,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line) p++; *p = '\0'; - if (!(v = OPENSSL_malloc(sizeof(*v)))) { + if ((v = OPENSSL_malloc(sizeof(*v))) == NULL) { CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/conf/conf_lib.c b/crypto/conf/conf_lib.c index 29e77c742b..838a6456a4 100644 --- a/crypto/conf/conf_lib.c +++ b/crypto/conf/conf_lib.c @@ -118,7 +118,7 @@ LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, { BIO *btmp; LHASH_OF(CONF_VALUE) *ltmp; - if (!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) { + if ((btmp = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) { CONFerr(CONF_F_CONF_LOAD_FP, ERR_R_BUF_LIB); return NULL; } @@ -200,7 +200,7 @@ int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out) BIO *btmp; int ret; - if (!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) { + if ((btmp = BIO_new_fp(out, BIO_NOCLOSE)) == NULL) { CONFerr(CONF_F_CONF_DUMP_FP, ERR_R_BUF_LIB); return 0; } @@ -270,7 +270,7 @@ int NCONF_load_fp(CONF *conf, FILE *fp, long *eline) { BIO *btmp; int ret; - if (!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) { + if ((btmp = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) { CONFerr(CONF_F_NCONF_LOAD_FP, ERR_R_BUF_LIB); return 0; } @@ -354,7 +354,7 @@ int NCONF_dump_fp(const CONF *conf, FILE *out) { BIO *btmp; int ret; - if (!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) { + if ((btmp = BIO_new_fp(out, BIO_NOCLOSE)) == NULL) { CONFerr(CONF_F_NCONF_DUMP_FP, ERR_R_BUF_LIB); return 0; } diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index b45173e2a8..065f8b9b54 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -119,18 +119,18 @@ static int dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) pm = pstr->data; pmlen = pstr->length; - if (!(dh = d2i_dhp(pkey, &pm, pmlen))) { + if ((dh = d2i_dhp(pkey, &pm, pmlen)) == NULL) { DHerr(DH_F_DH_PUB_DECODE, DH_R_DECODE_ERROR); goto err; } - if (!(public_key = d2i_ASN1_INTEGER(NULL, &p, pklen))) { + if ((public_key = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL) { DHerr(DH_F_DH_PUB_DECODE, DH_R_DECODE_ERROR); goto err; } /* We have parameters now set public key */ - if (!(dh->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) { + if ((dh->pub_key = ASN1_INTEGER_to_BN(public_key, NULL)) == NULL) { DHerr(DH_F_DH_PUB_DECODE, DH_R_BN_DECODE_ERROR); goto err; } @@ -218,17 +218,17 @@ static int dh_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) if (ptype != V_ASN1_SEQUENCE) goto decerr; - - if (!(privkey = d2i_ASN1_INTEGER(NULL, &p, pklen))) + if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL) goto decerr; pstr = pval; pm = pstr->data; pmlen = pstr->length; - if (!(dh = d2i_dhp(pkey, &pm, pmlen))) + if ((dh = d2i_dhp(pkey, &pm, pmlen)) == NULL) goto decerr; + /* We have parameters now set private key */ - if (!(dh->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) { + if ((dh->priv_key = ASN1_INTEGER_to_BN(privkey, NULL)) == NULL) { DHerr(DH_F_DH_PRIV_DECODE, DH_R_BN_ERROR); goto dherr; } @@ -310,7 +310,8 @@ static int dh_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) { DH *dh; - if (!(dh = d2i_dhp(pkey, pder, derlen))) { + + if ((dh = d2i_dhp(pkey, pder, derlen)) == NULL) { DHerr(DH_F_DH_PARAM_DECODE, ERR_R_DH_LIB); return 0; } @@ -679,13 +680,13 @@ static int dh_cms_set_peerkey(EVP_PKEY_CTX *pctx, if (!p || !plen) goto err; - if (!(public_key = d2i_ASN1_INTEGER(NULL, &p, plen))) { + if ((public_key = d2i_ASN1_INTEGER(NULL, &p, plen)) == NULL) { DHerr(DH_F_DH_CMS_SET_PEERKEY, DH_R_DECODE_ERROR); goto err; } /* We have parameters now set public key */ - if (!(dhpeer->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) { + if ((dhpeer->pub_key = ASN1_INTEGER_to_BN(public_key, NULL)) == NULL) { DHerr(DH_F_DH_CMS_SET_PEERKEY, DH_R_BN_DECODE_ERROR); goto err; } diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index e5009ec585..bc8fcc4424 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -88,13 +88,13 @@ static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) pm = pstr->data; pmlen = pstr->length; - if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) { + if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL) { DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR); goto err; } } else if ((ptype == V_ASN1_NULL) || (ptype == V_ASN1_UNDEF)) { - if (!(dsa = DSA_new())) { + if ((dsa = DSA_new()) == NULL) { DSAerr(DSA_F_DSA_PUB_DECODE, ERR_R_MALLOC_FAILURE); goto err; } @@ -103,12 +103,12 @@ static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) goto err; } - if (!(public_key = d2i_ASN1_INTEGER(NULL, &p, pklen))) { + if ((public_key = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL) { DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR); goto err; } - if (!(dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) { + if ((dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL)) == NULL) { DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_BN_DECODE_ERROR); goto err; } @@ -201,7 +201,7 @@ static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) /* Check for broken DSA PKCS#8, UGH! */ if (*p == (V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED)) { ASN1_TYPE *t1, *t2; - if (!(ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen))) + if ((ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen)) == NULL) goto decerr; if (sk_ASN1_TYPE_num(ndsa) != 2) goto decerr; @@ -227,12 +227,12 @@ static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) privkey = t2->value.integer; } else { const unsigned char *q = p; - if (!(privkey = d2i_ASN1_INTEGER(NULL, &p, pklen))) + if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL) goto decerr; if (privkey->type == V_ASN1_NEG_INTEGER) { p8->broken = PKCS8_NEG_PRIVKEY; ASN1_STRING_clear_free(privkey); - if (!(privkey = d2i_ASN1_UINTEGER(NULL, &q, pklen))) + if ((privkey = d2i_ASN1_UINTEGER(NULL, &q, pklen)) == NULL) goto decerr; } if (ptype != V_ASN1_SEQUENCE) @@ -242,19 +242,19 @@ static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) pstr = pval; pm = pstr->data; pmlen = pstr->length; - if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) + if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL) goto decerr; /* We have parameters now set private key */ - if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) { + if ((dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL)) == NULL) { DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR); goto dsaerr; } /* Calculate public key */ - if (!(dsa->pub_key = BN_new())) { + if ((dsa->pub_key = BN_new()) == NULL) { DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); goto dsaerr; } - if (!(ctx = BN_CTX_new())) { + if ((ctx = BN_CTX_new()) == NULL) { DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); goto dsaerr; } @@ -477,7 +477,8 @@ static int dsa_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) { DSA *dsa; - if (!(dsa = d2i_DSAparams(NULL, pder, derlen))) { + + if ((dsa = d2i_DSAparams(NULL, pder, derlen)) == NULL) { DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB); return 0; } @@ -512,7 +513,8 @@ static int old_dsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) { DSA *dsa; - if (!(dsa = d2i_DSAPrivateKey(NULL, pder, derlen))) { + + if ((dsa = d2i_DSAPrivateKey(NULL, pder, derlen)) == NULL) { DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB); return 0; } diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c index 1cc4d4003b..268eff05c9 100644 --- a/crypto/ec/ec_ameth.c +++ b/crypto/ec/ec_ameth.c @@ -145,7 +145,7 @@ static EC_KEY *eckey_type2param(int ptype, void *pval) int pmlen; pm = pstr->data; pmlen = pstr->length; - if (!(eckey = d2i_ECParameters(NULL, &pm, pmlen))) { + if ((eckey = d2i_ECParameters(NULL, &pm, pmlen)) == NULL) { ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR); goto ecerr; } @@ -510,7 +510,8 @@ static int eckey_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) { EC_KEY *eckey; - if (!(eckey = d2i_ECParameters(NULL, pder, derlen))) { + + if ((eckey = d2i_ECParameters(NULL, pder, derlen)) == NULL) { ECerr(EC_F_ECKEY_PARAM_DECODE, ERR_R_EC_LIB); return 0; } @@ -545,7 +546,8 @@ static int old_ec_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) { EC_KEY *ec; - if (!(ec = d2i_ECPrivateKey(NULL, pder, derlen))) { + + if ((ec = d2i_ECPrivateKey(NULL, pder, derlen)) == NULL) { ECerr(EC_F_OLD_EC_PRIV_DECODE, EC_R_DECODE_ERROR); return 0; } diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c index 638f849c16..ebafc10de7 100644 --- a/crypto/ec/ec_asn1.c +++ b/crypto/ec/ec_asn1.c @@ -838,7 +838,7 @@ static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params) /* extract seed (optional) */ if (params->curve->seed != NULL) { OPENSSL_free(ret->seed); - if (!(ret->seed = OPENSSL_malloc(params->curve->seed->length))) { + if ((ret->seed = OPENSSL_malloc(params->curve->seed->length)) == NULL) { ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/ec/ec_curve.c b/crypto/ec/ec_curve.c index 8f9308dbfd..f42fe3a175 100644 --- a/crypto/ec/ec_curve.c +++ b/crypto/ec/ec_curve.c @@ -3049,9 +3049,9 @@ static EC_GROUP *ec_group_new_from_data(const ec_list_element curve) params = (const unsigned char *)(data + 1); /* skip header */ params += seed_len; /* skip seed */ - if (!(p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) - || !(a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) - || !(b = BN_bin2bn(params + 2 * param_len, param_len, NULL))) { + if ((p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) == NULL + || (a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) == NULL + || (b = BN_bin2bn(params + 2 * param_len, param_len, NULL)) == NULL) { ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB); goto err; } @@ -3085,8 +3085,8 @@ static EC_GROUP *ec_group_new_from_data(const ec_list_element curve) goto err; } - if (!(x = BN_bin2bn(params + 3 * param_len, param_len, NULL)) - || !(y = BN_bin2bn(params + 4 * param_len, param_len, NULL))) { + if ((x = BN_bin2bn(params + 3 * param_len, param_len, NULL)) == NULL + || (y = BN_bin2bn(params + 4 * param_len, param_len, NULL)) == NULL) { ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB); goto err; } @@ -3094,7 +3094,7 @@ static EC_GROUP *ec_group_new_from_data(const ec_list_element curve) ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB); goto err; } - if (!(order = BN_bin2bn(params + 5 * param_len, param_len, NULL)) + if ((order = BN_bin2bn(params + 5 * param_len, param_len, NULL)) == NULL || !BN_set_word(x, (BN_ULONG)data->cofactor)) { ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB); goto err; diff --git a/crypto/ec/ec_mult.c b/crypto/ec/ec_mult.c index 9b75b9b739..09f042ee3a 100644 --- a/crypto/ec/ec_mult.c +++ b/crypto/ec/ec_mult.c @@ -465,7 +465,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, goto err; } - if (!(tmp = EC_POINT_new(group))) + if ((tmp = EC_POINT_new(group)) == NULL) goto err; /*- @@ -674,7 +674,8 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) } } - if (!(tmp_point = EC_POINT_new(group)) || !(base = EC_POINT_new(group))) { + if ((tmp_point = EC_POINT_new(group)) == NULL + || (base = EC_POINT_new(group)) == NULL) { ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/ec/ec_pmeth.c b/crypto/ec/ec_pmeth.c index 37d3efb314..42e3d3ae0f 100644 --- a/crypto/ec/ec_pmeth.c +++ b/crypto/ec/ec_pmeth.c @@ -427,7 +427,7 @@ static int pkey_ec_ctrl_str(EVP_PKEY_CTX *ctx, return EVP_PKEY_CTX_set_ec_param_enc(ctx, param_enc); } else if (strcmp(type, "ecdh_kdf_md") == 0) { const EVP_MD *md; - if (!(md = EVP_get_digestbyname(value))) { + if ((md = EVP_get_digestbyname(value)) == NULL) { ECerr(EC_F_PKEY_EC_CTRL_STR, EC_R_INVALID_DIGEST); return 0; } diff --git a/crypto/evp/evp_cnf.c b/crypto/evp/evp_cnf.c index 3073091cbe..11ee56ae54 100644 --- a/crypto/evp/evp_cnf.c +++ b/crypto/evp/evp_cnf.c @@ -74,8 +74,9 @@ static int alg_module_init(CONF_IMODULE *md, const CONF *cnf) const char *oid_section; STACK_OF(CONF_VALUE) *sktmp; CONF_VALUE *oval; + oid_section = CONF_imodule_get_value(md); - if (!(sktmp = NCONF_get_section(cnf, oid_section))) { + if ((sktmp = NCONF_get_section(cnf, oid_section)) == NULL) { EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_LOADING_SECTION); return 0; } diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c index 0f325076d4..63b3ad1852 100644 --- a/crypto/evp/evp_pbe.c +++ b/crypto/evp/evp_pbe.c @@ -227,9 +227,9 @@ int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, { EVP_PBE_CTL *pbe_tmp; - if (!pbe_algs) + if (pbe_algs == NULL) pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp); - if (!(pbe_tmp = OPENSSL_malloc(sizeof(*pbe_tmp)))) { + if ((pbe_tmp = OPENSSL_malloc(sizeof(*pbe_tmp))) == NULL) { EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE, ERR_R_MALLOC_FAILURE); return 0; } @@ -247,6 +247,7 @@ int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md, EVP_PBE_KEYGEN *keygen) { int cipher_nid, md_nid; + if (cipher) cipher_nid = EVP_CIPHER_nid(cipher); else diff --git a/crypto/evp/evp_pkey.c b/crypto/evp/evp_pkey.c index 7e64e26230..e987c4c9ad 100644 --- a/crypto/evp/evp_pkey.c +++ b/crypto/evp/evp_pkey.c @@ -75,7 +75,7 @@ EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8) if (!PKCS8_pkey_get0(&algoid, NULL, NULL, NULL, p8)) return NULL; - if (!(pkey = EVP_PKEY_new())) { + if ((pkey = EVP_PKEY_new()) == NULL) { EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_MALLOC_FAILURE); return NULL; } @@ -115,7 +115,7 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken) { PKCS8_PRIV_KEY_INFO *p8; - if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) { + if ((p8 = PKCS8_PRIV_KEY_INFO_new()) == NULL) { EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 10d974633d..fef0b8f260 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -416,7 +416,7 @@ int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, } if (strcmp(name, "digest") == 0) { const EVP_MD *md; - if (!value || !(md = EVP_get_digestbyname(value))) { + if (value == NULL || (md = EVP_get_digestbyname(value)) == NULL) { EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, EVP_R_INVALID_DIGEST); return 0; } diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c index 82af4a4006..991a1b7058 100644 --- a/crypto/objects/obj_dat.c +++ b/crypto/objects/obj_dat.c @@ -255,16 +255,16 @@ int OBJ_add_object(const ASN1_OBJECT *obj) return (0); if ((o = OBJ_dup(obj)) == NULL) goto err; - if (!(ao[ADDED_NID] = OPENSSL_malloc(sizeof(*ao)))) + if ((ao[ADDED_NID] = OPENSSL_malloc(sizeof(*ao))) == NULL) goto err2; if ((o->length != 0) && (obj->data != NULL)) - if (!(ao[ADDED_DATA] = OPENSSL_malloc(sizeof(*ao)))) + if ((ao[ADDED_DATA] = OPENSSL_malloc(sizeof(*ao))) == NULL) goto err2; if (o->sn != NULL) - if (!(ao[ADDED_SNAME] = OPENSSL_malloc(sizeof(*ao)))) + if ((ao[ADDED_SNAME] = OPENSSL_malloc(sizeof(*ao))) == NULL) goto err2; if (o->ln != NULL) - if (!(ao[ADDED_LNAME] = OPENSSL_malloc(sizeof(*ao)))) + if ((ao[ADDED_LNAME] = OPENSSL_malloc(sizeof(*ao))) == NULL) goto err2; for (i = ADDED_DATA; i <= ADDED_NID; i++) { @@ -507,7 +507,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) if (!(c & 0x80)) break; if (!use_bn && (l > (ULONG_MAX >> 7L))) { - if (!bl && !(bl = BN_new())) + if (bl == NULL && (bl = BN_new()) == NULL) goto err; if (!BN_set_word(bl, l)) goto err; diff --git a/crypto/ocsp/ocsp_cl.c b/crypto/ocsp/ocsp_cl.c index 0f3f13faf8..b6ec19a565 100644 --- a/crypto/ocsp/ocsp_cl.c +++ b/crypto/ocsp/ocsp_cl.c @@ -89,7 +89,7 @@ OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid) { OCSP_ONEREQ *one = NULL; - if (!(one = OCSP_ONEREQ_new())) + if ((one = OCSP_ONEREQ_new()) == NULL) goto err; OCSP_CERTID_free(one->reqCert); one->reqCert = cid; @@ -132,7 +132,8 @@ int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert) return 0; if (!cert) return 1; - if (!sig->certs && !(sig->certs = sk_X509_new_null())) + if (sig->certs == NULL + && (sig->certs = sk_X509_new_null()) == NULL) return 0; if (!sk_X509_push(sig->certs, cert)) @@ -159,7 +160,7 @@ int OCSP_request_sign(OCSP_REQUEST *req, if (!OCSP_request_set1_name(req, X509_get_subject_name(signer))) goto err; - if (!(req->optionalSignature = OCSP_SIGNATURE_new())) + if ((req->optionalSignature = OCSP_SIGNATURE_new()) == NULL) goto err; if (key) { if (!X509_check_private_key(signer, key)) { diff --git a/crypto/ocsp/ocsp_ext.c b/crypto/ocsp/ocsp_ext.c index 8a35f752b2..63a8332c15 100644 --- a/crypto/ocsp/ocsp_ext.c +++ b/crypto/ocsp/ocsp_ext.c @@ -415,22 +415,22 @@ X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim) X509_EXTENSION *x = NULL; OCSP_CRLID *cid = NULL; - if (!(cid = OCSP_CRLID_new())) + if ((cid = OCSP_CRLID_new()) == NULL) goto err; if (url) { - if (!(cid->crlUrl = ASN1_IA5STRING_new())) + if ((cid->crlUrl = ASN1_IA5STRING_new()) == NULL) goto err; if (!(ASN1_STRING_set(cid->crlUrl, url, -1))) goto err; } if (n) { - if (!(cid->crlNum = ASN1_INTEGER_new())) + if ((cid->crlNum = ASN1_INTEGER_new()) == NULL) goto err; if (!(ASN1_INTEGER_set(cid->crlNum, *n))) goto err; } if (tim) { - if (!(cid->crlTime = ASN1_GENERALIZEDTIME_new())) + if ((cid->crlTime = ASN1_GENERALIZEDTIME_new()) == NULL) goto err; if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim))) goto err; @@ -449,7 +449,7 @@ X509_EXTENSION *OCSP_accept_responses_new(char **oids) ASN1_OBJECT *o = NULL; X509_EXTENSION *x = NULL; - if (!(sk = sk_ASN1_OBJECT_new_null())) + if ((sk = sk_ASN1_OBJECT_new_null()) == NULL) goto err; while (oids && *oids) { if ((nid = OBJ_txt2nid(*oids)) != NID_undef && (o = OBJ_nid2obj(nid))) @@ -468,7 +468,7 @@ X509_EXTENSION *OCSP_archive_cutoff_new(char *tim) X509_EXTENSION *x = NULL; ASN1_GENERALIZEDTIME *gt = NULL; - if (!(gt = ASN1_GENERALIZEDTIME_new())) + if ((gt = ASN1_GENERALIZEDTIME_new()) == NULL) goto err; if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err; @@ -490,20 +490,21 @@ X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, char **urls) OCSP_SERVICELOC *sloc = NULL; ACCESS_DESCRIPTION *ad = NULL; - if (!(sloc = OCSP_SERVICELOC_new())) + if ((sloc = OCSP_SERVICELOC_new()) == NULL) goto err; - if (!(sloc->issuer = X509_NAME_dup(issuer))) + if ((sloc->issuer = X509_NAME_dup(issuer)) == NULL) goto err; - if (urls && *urls && !(sloc->locator = sk_ACCESS_DESCRIPTION_new_null())) + if (urls && *urls + && (sloc->locator = sk_ACCESS_DESCRIPTION_new_null()) == NULL) goto err; while (urls && *urls) { - if (!(ad = ACCESS_DESCRIPTION_new())) + if ((ad = ACCESS_DESCRIPTION_new()) == NULL) goto err; - if (!(ad->method = OBJ_nid2obj(NID_ad_OCSP))) + if ((ad->method = OBJ_nid2obj(NID_ad_OCSP)) == NULL) goto err; - if (!(ad->location = GENERAL_NAME_new())) + if ((ad->location = GENERAL_NAME_new()) == NULL) goto err; - if (!(ia5 = ASN1_IA5STRING_new())) + if ((ia5 = ASN1_IA5STRING_new()) == NULL) goto err; if (!ASN1_STRING_set((ASN1_STRING *)ia5, *urls, -1)) goto err; diff --git a/crypto/ocsp/ocsp_lib.c b/crypto/ocsp/ocsp_lib.c index 1f383f6c83..b0e7122796 100644 --- a/crypto/ocsp/ocsp_lib.c +++ b/crypto/ocsp/ocsp_lib.c @@ -106,7 +106,7 @@ OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, OCSP_CERTID *cid = NULL; unsigned char md[EVP_MAX_MD_SIZE]; - if (!(cid = OCSP_CERTID_new())) + if ((cid = OCSP_CERTID_new()) == NULL) goto err; alg = cid->hashAlgorithm; @@ -115,7 +115,7 @@ OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, OCSPerr(OCSP_F_OCSP_CERT_ID_NEW, OCSP_R_UNKNOWN_NID); goto err; } - if (!(alg->algorithm = OBJ_nid2obj(nid))) + if ((alg->algorithm = OBJ_nid2obj(nid)) == NULL) goto err; if ((alg->parameter = ASN1_TYPE_new()) == NULL) goto err; @@ -135,7 +135,7 @@ OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, if (serialNumber) { ASN1_INTEGER_free(cid->serialNumber); - if (!(cid->serialNumber = ASN1_INTEGER_dup(serialNumber))) + if ((cid->serialNumber = ASN1_INTEGER_dup(serialNumber)) == NULL) goto err; } return cid; diff --git a/crypto/ocsp/ocsp_prn.c b/crypto/ocsp/ocsp_prn.c index 96c2023450..b826292df8 100644 --- a/crypto/ocsp/ocsp_prn.c +++ b/crypto/ocsp/ocsp_prn.c @@ -214,7 +214,7 @@ int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE *o, unsigned long flags) } i = ASN1_STRING_length(rb->response); - if (!(br = OCSP_response_get1_basic(o))) + if ((br = OCSP_response_get1_basic(o)) == NULL) goto err; rd = br->tbsResponseData; l = ASN1_INTEGER_get(rd->version); diff --git a/crypto/ocsp/ocsp_srv.c b/crypto/ocsp/ocsp_srv.c index 1afa68cfd7..3b71dd7e85 100644 --- a/crypto/ocsp/ocsp_srv.c +++ b/crypto/ocsp/ocsp_srv.c @@ -116,13 +116,13 @@ OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs) { OCSP_RESPONSE *rsp = NULL; - if (!(rsp = OCSP_RESPONSE_new())) + if ((rsp = OCSP_RESPONSE_new()) == NULL) goto err; if (!(ASN1_ENUMERATED_set(rsp->responseStatus, status))) goto err; if (!bs) return rsp; - if (!(rsp->responseBytes = OCSP_RESPBYTES_new())) + if ((rsp->responseBytes = OCSP_RESPBYTES_new()) == NULL) goto err; rsp->responseBytes->responseType = OBJ_nid2obj(NID_id_pkix_OCSP_basic); if (!ASN1_item_pack @@ -145,11 +145,12 @@ OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, OCSP_CERTSTATUS *cs; OCSP_REVOKEDINFO *ri; - if (!rsp->tbsResponseData->responses && - !(rsp->tbsResponseData->responses = sk_OCSP_SINGLERESP_new_null())) + if (rsp->tbsResponseData->responses == NULL + && (rsp->tbsResponseData->responses + = sk_OCSP_SINGLERESP_new_null()) == NULL) goto err; - if (!(single = OCSP_SINGLERESP_new())) + if ((single = OCSP_SINGLERESP_new()) == NULL) goto err; if (!ASN1_TIME_to_generalizedtime(thisupd, &single->thisUpdate)) @@ -160,7 +161,7 @@ OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, OCSP_CERTID_free(single->certId); - if (!(single->certId = OCSP_CERTID_dup(cid))) + if ((single->certId = OCSP_CERTID_dup(cid)) == NULL) goto err; cs = single->certStatus; @@ -170,12 +171,12 @@ OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, OCSPerr(OCSP_F_OCSP_BASIC_ADD1_STATUS, OCSP_R_NO_REVOKED_TIME); goto err; } - if (!(cs->value.revoked = ri = OCSP_REVOKEDINFO_new())) + if ((cs->value.revoked = ri = OCSP_REVOKEDINFO_new()) == NULL) goto err; if (!ASN1_TIME_to_generalizedtime(revtime, &ri->revocationTime)) goto err; if (reason != OCSP_REVOKED_STATUS_NOSTATUS) { - if (!(ri->revocationReason = ASN1_ENUMERATED_new())) + if ((ri->revocationReason = ASN1_ENUMERATED_new()) == NULL) goto err; if (!(ASN1_ENUMERATED_set(ri->revocationReason, reason))) goto err; @@ -206,7 +207,8 @@ OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert) { - if (!resp->certs && !(resp->certs = sk_X509_new_null())) + if (resp->certs == NULL + && (resp->certs = sk_X509_new_null()) == NULL) return 0; if (!sk_X509_push(resp->certs, cert)) @@ -242,7 +244,7 @@ int OCSP_basic_sign(OCSP_BASICRESP *brsp, if (flags & OCSP_RESPID_KEY) { unsigned char md[SHA_DIGEST_LENGTH]; X509_pubkey_digest(signer, EVP_sha1(), md, NULL); - if (!(rid->value.byKey = ASN1_OCTET_STRING_new())) + if ((rid->value.byKey = ASN1_OCTET_STRING_new()) == NULL) goto err; if (!(ASN1_OCTET_STRING_set(rid->value.byKey, md, SHA_DIGEST_LENGTH))) goto err; diff --git a/crypto/ocsp/ocsp_vfy.c b/crypto/ocsp/ocsp_vfy.c index 9bf1ff502a..d2693c7c54 100644 --- a/crypto/ocsp/ocsp_vfy.c +++ b/crypto/ocsp/ocsp_vfy.c @@ -314,7 +314,8 @@ static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid, X509_NAME *iname; int mdlen; unsigned char md[EVP_MAX_MD_SIZE]; - if (!(dgst = EVP_get_digestbyobj(cid->hashAlgorithm->algorithm))) { + if ((dgst = EVP_get_digestbyobj(cid->hashAlgorithm->algorithm)) + == NULL) { OCSPerr(OCSP_F_OCSP_MATCH_ISSUERID, OCSP_R_UNKNOWN_MESSAGE_DIGEST); return -1; diff --git a/crypto/pem/pem_pk8.c b/crypto/pem/pem_pk8.c index 529d077a9a..52b40fe5ea 100644 --- a/crypto/pem/pem_pk8.c +++ b/crypto/pem/pem_pk8.c @@ -116,7 +116,8 @@ static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, PKCS8_PRIV_KEY_INFO *p8inf; char buf[PEM_BUFSIZE]; int ret; - if (!(p8inf = EVP_PKEY2PKCS8(x))) { + + if ((p8inf = EVP_PKEY2PKCS8(x)) == NULL) { PEMerr(PEM_F_DO_PK8PKEY, PEM_R_ERROR_CONVERTING_PRIVATE_KEY); return 0; } @@ -224,7 +225,8 @@ static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, { BIO *bp; int ret; - if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { + + if ((bp = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) { PEMerr(PEM_F_DO_PK8PKEY_FP, ERR_R_BUF_LIB); return (0); } @@ -238,7 +240,8 @@ EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, { BIO *bp; EVP_PKEY *ret; - if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { + + if ((bp = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) { PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP, ERR_R_BUF_LIB); return NULL; } diff --git a/crypto/pem/pvkfmt.c b/crypto/pem/pvkfmt.c index d2a5952c9e..0900ef603b 100644 --- a/crypto/pem/pvkfmt.c +++ b/crypto/pem/pvkfmt.c @@ -316,13 +316,12 @@ static EVP_PKEY *b2i_dss(const unsigned char **in, unsigned int length, if (!read_lebn(&p, 20, &dsa->priv_key)) goto memerr; /* Calculate public key */ - if (!(dsa->pub_key = BN_new())) + if ((dsa->pub_key = BN_new()) == NULL) goto memerr; - if (!(ctx = BN_CTX_new())) + if ((ctx = BN_CTX_new()) == NULL) goto memerr; if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) - goto memerr; BN_CTX_free(ctx); } diff --git a/crypto/pkcs12/p12_add.c b/crypto/pkcs12/p12_add.c index 51ea42a886..301fed65f9 100644 --- a/crypto/pkcs12/p12_add.c +++ b/crypto/pkcs12/p12_add.c @@ -68,7 +68,8 @@ PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, { PKCS12_BAGS *bag; PKCS12_SAFEBAG *safebag; - if (!(bag = PKCS12_BAGS_new())) { + + if ((bag = PKCS12_BAGS_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); return NULL; } @@ -77,7 +78,7 @@ PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); return NULL; } - if (!(safebag = PKCS12_SAFEBAG_new())) { + if ((safebag = PKCS12_SAFEBAG_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); return NULL; } @@ -91,7 +92,8 @@ PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8) { PKCS12_SAFEBAG *bag; - if (!(bag = PKCS12_SAFEBAG_new())) { + + if ((bag = PKCS12_SAFEBAG_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_MAKE_KEYBAG, ERR_R_MALLOC_FAILURE); return NULL; } @@ -111,7 +113,7 @@ PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, const EVP_CIPHER *pbe_ciph; /* Set up the safe bag */ - if (!(bag = PKCS12_SAFEBAG_new())) { + if ((bag = PKCS12_SAFEBAG_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE); return NULL; } @@ -137,12 +139,13 @@ PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk) { PKCS7 *p7; - if (!(p7 = PKCS7_new())) { + + if ((p7 = PKCS7_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); return NULL; } p7->type = OBJ_nid2obj(NID_pkcs7_data); - if (!(p7->d.data = ASN1_OCTET_STRING_new())) { + if ((p7->d.data = ASN1_OCTET_STRING_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); return NULL; } @@ -174,7 +177,8 @@ PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, PKCS7 *p7; X509_ALGOR *pbe; const EVP_CIPHER *pbe_ciph; - if (!(p7 = PKCS7_new())) { + + if ((p7 = PKCS7_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/pkcs12/p12_attr.c b/crypto/pkcs12/p12_attr.c index 70695b7bb6..365a1cdff6 100644 --- a/crypto/pkcs12/p12_attr.c +++ b/crypto/pkcs12/p12_attr.c @@ -129,7 +129,8 @@ ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid) char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag) { ASN1_TYPE *atype; - if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) + + if ((atype = PKCS12_get_attr(bag, NID_friendlyName)) == NULL) return NULL; if (atype->type != V_ASN1_BMPSTRING) return NULL; diff --git a/crypto/pkcs12/p12_crt.c b/crypto/pkcs12/p12_crt.c index fcc77cd2fc..cc254109da 100644 --- a/crypto/pkcs12/p12_crt.c +++ b/crypto/pkcs12/p12_crt.c @@ -189,7 +189,7 @@ PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert) int keyidlen = -1; /* Add user certificate */ - if (!(bag = PKCS12_x5092certbag(cert))) + if ((bag = PKCS12_x5092certbag(cert)) == NULL) goto err; /* @@ -226,7 +226,7 @@ PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, PKCS8_PRIV_KEY_INFO *p8 = NULL; /* Make a PKCS#8 structure */ - if (!(p8 = EVP_PKEY2PKCS8(key))) + if ((p8 = EVP_PKEY2PKCS8(key)) == NULL) goto err; if (key_usage && !PKCS8_add_keyusage(p8, key_usage)) goto err; diff --git a/crypto/pkcs12/p12_decr.c b/crypto/pkcs12/p12_decr.c index 19efd967d8..5154e545fe 100644 --- a/crypto/pkcs12/p12_decr.c +++ b/crypto/pkcs12/p12_decr.c @@ -88,7 +88,8 @@ unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, return NULL; } - if (!(out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) { + if ((out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx))) + == NULL) { PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -174,7 +175,8 @@ ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, ASN1_OCTET_STRING *oct = NULL; unsigned char *in = NULL; int inlen; - if (!(oct = ASN1_OCTET_STRING_new())) { + + if ((oct = ASN1_OCTET_STRING_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/pkcs12/p12_init.c b/crypto/pkcs12/p12_init.c index 22fa10e865..29f98316bf 100644 --- a/crypto/pkcs12/p12_init.c +++ b/crypto/pkcs12/p12_init.c @@ -66,7 +66,8 @@ PKCS12 *PKCS12_init(int mode) { PKCS12 *pkcs12; - if (!(pkcs12 = PKCS12_new())) { + + if ((pkcs12 = PKCS12_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE); return NULL; } @@ -74,7 +75,7 @@ PKCS12 *PKCS12_init(int mode) pkcs12->authsafes->type = OBJ_nid2obj(mode); switch (mode) { case NID_pkcs7_data: - if (!(pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new())) { + if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/pkcs12/p12_kiss.c b/crypto/pkcs12/p12_kiss.c index cd1842789f..a2dbc42eab 100644 --- a/crypto/pkcs12/p12_kiss.c +++ b/crypto/pkcs12/p12_kiss.c @@ -179,7 +179,7 @@ static int parse_pk12(PKCS12 *p12, const char *pass, int passlen, int i, bagnid; PKCS7 *p7; - if (!(asafes = PKCS12_unpack_authsafes(p12))) + if ((asafes = PKCS12_unpack_authsafes(p12)) == NULL) return 0; for (i = 0; i < sk_PKCS7_num(asafes); i++) { p7 = sk_PKCS7_value(asafes, i); @@ -236,14 +236,14 @@ static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen, case NID_keyBag: if (!pkey || *pkey) return 1; - if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag))) + if ((*pkey = EVP_PKCS82PKEY(bag->value.keybag)) == NULL) return 0; break; case NID_pkcs8ShroudedKeyBag: if (!pkey || *pkey) return 1; - if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen))) + if ((p8 = PKCS12_decrypt_skey(bag, pass, passlen)) == NULL) return 0; *pkey = EVP_PKCS82PKEY(p8); PKCS8_PRIV_KEY_INFO_free(p8); @@ -254,7 +254,7 @@ static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen, case NID_certBag: if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate) return 1; - if (!(x509 = PKCS12_certbag2x509(bag))) + if ((x509 = PKCS12_certbag2x509(bag)) == NULL) return 0; if (lkid && !X509_keyid_set1(x509, lkid->data, lkid->length)) { X509_free(x509); diff --git a/crypto/pkcs12/p12_mutl.c b/crypto/pkcs12/p12_mutl.c index 252aca0021..b193da1b3d 100644 --- a/crypto/pkcs12/p12_mutl.c +++ b/crypto/pkcs12/p12_mutl.c @@ -84,7 +84,8 @@ int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, iter = 1; else iter = ASN1_INTEGER_get(p12->mac->iter); - if (!(md_type = EVP_get_digestbyobj(p12->mac->dinfo->algor->algorithm))) { + if ((md_type = EVP_get_digestbyobj(p12->mac->dinfo->algor->algorithm)) + == NULL) { PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_UNKNOWN_DIGEST_ALGORITHM); return 0; } @@ -157,10 +158,10 @@ int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen, const EVP_MD *md_type) { - if (!(p12->mac = PKCS12_MAC_DATA_new())) + if ((p12->mac = PKCS12_MAC_DATA_new()) == NULL) return PKCS12_ERROR; if (iter > 1) { - if (!(p12->mac->iter = ASN1_INTEGER_new())) { + if ((p12->mac->iter = ASN1_INTEGER_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); return 0; } @@ -172,7 +173,7 @@ int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen, if (!saltlen) saltlen = PKCS12_SALT_LEN; p12->mac->salt->length = saltlen; - if (!(p12->mac->salt->data = OPENSSL_malloc(saltlen))) { + if ((p12->mac->salt->data = OPENSSL_malloc(saltlen)) == NULL) { PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); return 0; } @@ -182,7 +183,7 @@ int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen, } else memcpy(p12->mac->salt->data, salt, saltlen); p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); - if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { + if ((p12->mac->dinfo->algor->parameter = ASN1_TYPE_new()) == NULL) { PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/pkcs12/p12_npas.c b/crypto/pkcs12/p12_npas.c index f756033fc4..c402428f57 100644 --- a/crypto/pkcs12/p12_npas.c +++ b/crypto/pkcs12/p12_npas.c @@ -113,9 +113,9 @@ static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) unsigned char mac[EVP_MAX_MD_SIZE]; unsigned int maclen; - if (!(asafes = PKCS12_unpack_authsafes(p12))) + if ((asafes = PKCS12_unpack_authsafes(p12)) == NULL) return 0; - if (!(newsafes = sk_PKCS7_new_null())) + if ((newsafes = sk_PKCS7_new_null()) == NULL) return 0; for (i = 0; i < sk_PKCS7_num(asafes); i++) { p7 = sk_PKCS7_value(asafes, i); @@ -158,14 +158,14 @@ static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) /* Repack safe: save old safe in case of error */ p12_data_tmp = p12->authsafes->d.data; - if (!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) + if ((p12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) goto saferr; if (!PKCS12_pack_authsafes(p12, newsafes)) goto saferr; if (!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr; - if (!(macnew = ASN1_OCTET_STRING_new())) + if ((macnew = ASN1_OCTET_STRING_new()) == NULL) goto saferr; if (!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr; @@ -206,12 +206,12 @@ static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass) if (M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) return 1; - if (!(p8 = PKCS8_decrypt(bag->value.shkeybag, oldpass, -1))) + if ((p8 = PKCS8_decrypt(bag->value.shkeybag, oldpass, -1)) == NULL) return 0; if (!alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter, &p8_saltlen)) return 0; - if (!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen, - p8_iter, p8))) + if ((p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen, + p8_iter, p8)) == NULL) return 0; X509_SIG_free(bag->value.shkeybag); bag->value.shkeybag = p8new; diff --git a/crypto/pkcs12/p12_p8e.c b/crypto/pkcs12/p12_p8e.c index 02757425b9..9375cbfc56 100644 --- a/crypto/pkcs12/p12_p8e.c +++ b/crypto/pkcs12/p12_p8e.c @@ -66,10 +66,10 @@ X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8inf) { - X509_SIG *p8 = NULL; + X509_SIG *p8; X509_ALGOR *pbe; - if (!(p8 = X509_SIG_new())) { + if ((p8 = X509_SIG_new()) == NULL) { PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/pkcs12/p12_utl.c b/crypto/pkcs12/p12_utl.c index 454681525d..c55a4f18c9 100644 --- a/crypto/pkcs12/p12_utl.c +++ b/crypto/pkcs12/p12_utl.c @@ -68,10 +68,11 @@ unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, { int ulen, i; unsigned char *unitmp; + if (asclen == -1) asclen = strlen(asc); ulen = asclen * 2 + 2; - if (!(unitmp = OPENSSL_malloc(ulen))) + if ((unitmp = OPENSSL_malloc(ulen)) == NULL) return NULL; for (i = 0; i < ulen - 2; i += 2) { unitmp[i] = 0; @@ -91,12 +92,13 @@ char *OPENSSL_uni2asc(unsigned char *uni, int unilen) { int asclen, i; char *asctmp; + asclen = unilen / 2; /* If no terminating zero allow for one */ if (!unilen || uni[unilen - 1]) asclen++; uni++; - if (!(asctmp = OPENSSL_malloc(asclen))) + if ((asctmp = OPENSSL_malloc(asclen)) == NULL) return NULL; for (i = 0; i < unilen; i += 2) asctmp[i >> 1] = uni[i]; diff --git a/crypto/pkcs7/pk7_attr.c b/crypto/pkcs7/pk7_attr.c index 88922efe27..ef2386ba3c 100644 --- a/crypto/pkcs7/pk7_attr.c +++ b/crypto/pkcs7/pk7_attr.c @@ -71,7 +71,8 @@ int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap) { ASN1_STRING *seq; - if (!(seq = ASN1_STRING_new())) { + + if ((seq = ASN1_STRING_new()) == NULL) { PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP, ERR_R_MALLOC_FAILURE); return 0; } @@ -87,7 +88,7 @@ STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si) const unsigned char *p; cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities); - if (!cap || (cap->type != V_ASN1_SEQUENCE)) + if (cap == NULL || (cap->type != V_ASN1_SEQUENCE)) return NULL; p = cap->value.sequence->data; return (STACK_OF(X509_ALGOR) *) @@ -100,7 +101,7 @@ int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg) { X509_ALGOR *alg; - if (!(alg = X509_ALGOR_new())) { + if ((alg = X509_ALGOR_new()) == NULL) { PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP, ERR_R_MALLOC_FAILURE); return 0; } @@ -108,11 +109,11 @@ int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg) alg->algorithm = OBJ_nid2obj(nid); if (arg > 0) { ASN1_INTEGER *nbit; - if (!(alg->parameter = ASN1_TYPE_new())) { + if ((alg->parameter = ASN1_TYPE_new()) == NULL) { PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP, ERR_R_MALLOC_FAILURE); return 0; } - if (!(nbit = ASN1_INTEGER_new())) { + if ((nbit = ASN1_INTEGER_new()) == NULL) { PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP, ERR_R_MALLOC_FAILURE); return 0; } @@ -139,7 +140,7 @@ int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid) int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t) { - if (!t && !(t = X509_gmtime_adj(NULL, 0))) { + if (t == NULL && (t = X509_gmtime_adj(NULL, 0)) == NULL) { PKCS7err(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME, ERR_R_MALLOC_FAILURE); return 0; diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c index e5ad95fb1d..bdbde21150 100644 --- a/crypto/pkcs7/pk7_doit.c +++ b/crypto/pkcs7/pk7_doit.c @@ -1104,7 +1104,7 @@ static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid) ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk) { ASN1_TYPE *astype; - if (!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) + if ((astype = get_attribute(sk, NID_pkcs9_messageDigest)) == NULL) return NULL; return astype->value.octet_string; } @@ -1165,11 +1165,10 @@ static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, X509_ATTRIBUTE *attr = NULL; if (*sk == NULL) { - *sk = sk_X509_ATTRIBUTE_new_null(); - if (*sk == NULL) + if ((*sk = sk_X509_ATTRIBUTE_new_null()) == NULL) return 0; new_attrib: - if (!(attr = X509_ATTRIBUTE_create(nid, atrtype, value))) + if ((attr = X509_ATTRIBUTE_create(nid, atrtype, value)) == NULL) return 0; if (!sk_X509_ATTRIBUTE_push(*sk, attr)) { X509_ATTRIBUTE_free(attr); diff --git a/crypto/pkcs7/pk7_lib.c b/crypto/pkcs7/pk7_lib.c index e14d8c6c3c..30cc98fbe5 100644 --- a/crypto/pkcs7/pk7_lib.c +++ b/crypto/pkcs7/pk7_lib.c @@ -265,8 +265,8 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi) } } if (!j) { /* we need to add another algorithm */ - if (!(alg = X509_ALGOR_new()) - || !(alg->parameter = ASN1_TYPE_new())) { + if ((alg = X509_ALGOR_new()) == NULL + || (alg->parameter = ASN1_TYPE_new()) == NULL) { X509_ALGOR_free(alg); PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER, ERR_R_MALLOC_FAILURE); return (0); @@ -426,7 +426,7 @@ PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey, int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md) { if (PKCS7_type_is_digest(p7)) { - if (!(p7->d.digest->md->parameter = ASN1_TYPE_new())) { + if ((p7->d.digest->md->parameter = ASN1_TYPE_new()) == NULL) { PKCS7err(PKCS7_F_PKCS7_SET_DIGEST, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/pkcs7/pk7_smime.c b/crypto/pkcs7/pk7_smime.c index 33bdda2be6..edc5969d34 100644 --- a/crypto/pkcs7/pk7_smime.c +++ b/crypto/pkcs7/pk7_smime.c @@ -72,7 +72,7 @@ PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, PKCS7 *p7; int i; - if (!(p7 = PKCS7_new())) { + if ((p7 = PKCS7_new()) == NULL) { PKCS7err(PKCS7_F_PKCS7_SIGN, ERR_R_MALLOC_FAILURE); return NULL; } @@ -113,7 +113,7 @@ int PKCS7_final(PKCS7 *p7, BIO *data, int flags) { BIO *p7bio; int ret = 0; - if (!(p7bio = PKCS7_dataInit(p7, NULL))) { + if ((p7bio = PKCS7_dataInit(p7, NULL)) == NULL) { PKCS7err(PKCS7_F_PKCS7_FINAL, ERR_R_MALLOC_FAILURE); return 0; } @@ -164,7 +164,7 @@ PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, return NULL; } - if (!(si = PKCS7_add_signature(p7, signcert, pkey, md))) { + if ((si = PKCS7_add_signature(p7, signcert, pkey, md)) == NULL) { PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER, PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR); return NULL; @@ -180,7 +180,7 @@ PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, goto err; /* Add SMIMECapabilities */ if (!(flags & PKCS7_NOSMIMECAP)) { - if (!(smcap = sk_X509_ALGOR_new_null())) { + if ((smcap = sk_X509_ALGOR_new_null()) == NULL) { PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER, ERR_R_MALLOC_FAILURE); goto err; } @@ -353,11 +353,11 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, } else tmpin = indata; - if (!(p7bio = PKCS7_dataInit(p7, tmpin))) + if ((p7bio = PKCS7_dataInit(p7, tmpin)) == NULL) goto err; if (flags & PKCS7_TEXT) { - if (!(tmpout = BIO_new(BIO_s_mem()))) { + if ((tmpout = BIO_new(BIO_s_mem())) == NULL) { PKCS7err(PKCS7_F_PKCS7_VERIFY, ERR_R_MALLOC_FAILURE); goto err; } @@ -439,7 +439,7 @@ STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, return 0; } - if (!(signers = sk_X509_new_null())) { + if ((signers = sk_X509_new_null()) == NULL) { PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS, ERR_R_MALLOC_FAILURE); return NULL; } @@ -481,7 +481,7 @@ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, BIO *p7bio = NULL; int i; X509 *x509; - if (!(p7 = PKCS7_new())) { + if ((p7 = PKCS7_new()) == NULL) { PKCS7err(PKCS7_F_PKCS7_ENCRYPT, ERR_R_MALLOC_FAILURE); return NULL; } @@ -537,7 +537,7 @@ int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags) return 0; } - if (!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) { + if ((tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert)) == NULL) { PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR); return 0; } @@ -545,12 +545,12 @@ int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags) if (flags & PKCS7_TEXT) { BIO *tmpbuf, *bread; /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */ - if (!(tmpbuf = BIO_new(BIO_f_buffer()))) { + if ((tmpbuf = BIO_new(BIO_f_buffer())) == NULL) { PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); BIO_free_all(tmpmem); return 0; } - if (!(bread = BIO_push(tmpbuf, tmpmem))) { + if ((bread = BIO_push(tmpbuf, tmpmem)) == NULL) { PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); BIO_free_all(tmpbuf); BIO_free_all(tmpmem); diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index e9ccd7e41d..509f203a09 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -93,9 +93,10 @@ static int rsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) const unsigned char *p; int pklen; RSA *rsa = NULL; + if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, NULL, pubkey)) return 0; - if (!(rsa = d2i_RSAPublicKey(NULL, &p, pklen))) { + if ((rsa = d2i_RSAPublicKey(NULL, &p, pklen)) == NULL) { RSAerr(RSA_F_RSA_PUB_DECODE, ERR_R_RSA_LIB); return 0; } @@ -115,7 +116,8 @@ static int old_rsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) { RSA *rsa; - if (!(rsa = d2i_RSAPrivateKey(NULL, pder, derlen))) { + + if ((rsa = d2i_RSAPrivateKey(NULL, pder, derlen)) == NULL) { RSAerr(RSA_F_OLD_RSA_PRIV_DECODE, ERR_R_RSA_LIB); return 0; } diff --git a/crypto/rsa/rsa_pmeth.c b/crypto/rsa/rsa_pmeth.c index ced7232fdf..76d5c6914d 100644 --- a/crypto/rsa/rsa_pmeth.c +++ b/crypto/rsa/rsa_pmeth.c @@ -606,7 +606,7 @@ static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, if (strcmp(type, "rsa_mgf1_md") == 0) { const EVP_MD *md; - if (!(md = EVP_get_digestbyname(value))) { + if ((md = EVP_get_digestbyname(value)) == NULL) { RSAerr(RSA_F_PKEY_RSA_CTRL_STR, RSA_R_INVALID_DIGEST); return 0; } @@ -615,7 +615,7 @@ static int pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, if (strcmp(type, "rsa_oaep_md") == 0) { const EVP_MD *md; - if (!(md = EVP_get_digestbyname(value))) { + if ((md = EVP_get_digestbyname(value)) == NULL) { RSAerr(RSA_F_PKEY_RSA_CTRL_STR, RSA_R_INVALID_DIGEST); return 0; } diff --git a/crypto/srp/srp_lib.c b/crypto/srp/srp_lib.c index 7a47acd039..1b263199f1 100644 --- a/crypto/srp/srp_lib.c +++ b/crypto/srp/srp_lib.c @@ -127,7 +127,7 @@ BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N) EVP_DigestFinal_ex(&ctxt, cu, NULL); EVP_MD_CTX_cleanup(&ctxt); - if (!(u = BN_bin2bn(cu, sizeof(cu), NULL))) + if ((u = BN_bin2bn(cu, sizeof(cu), NULL)) == NULL) return NULL; if (!BN_is_zero(u)) return u; @@ -178,10 +178,10 @@ BIGNUM *SRP_Calc_B(BIGNUM *b, BIGNUM *N, BIGNUM *g, BIGNUM *v) /* B = g**b + k*v */ - if (!BN_mod_exp(gb, g, b, N, bn_ctx) || - !(k = srp_Calc_k(N, g)) || - !BN_mod_mul(kv, v, k, N, bn_ctx) || - !BN_mod_add(B, gb, kv, N, bn_ctx)) { + if (!BN_mod_exp(gb, g, b, N, bn_ctx) + || (k = srp_Calc_k(N, g)) == NULL + || !BN_mod_mul(kv, v, k, N, bn_ctx) + || !BN_mod_add(B, gb, kv, N, bn_ctx)) { BN_free(B); B = NULL; } @@ -257,13 +257,12 @@ BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, if (!BN_mod_exp(tmp, g, x, N, bn_ctx)) goto err; - if (!(k = srp_Calc_k(N, g))) + if ((k = srp_Calc_k(N, g)) == NULL) goto err; if (!BN_mod_mul(tmp2, tmp, k, N, bn_ctx)) goto err; if (!BN_mod_sub(tmp, B, tmp2, N, bn_ctx)) goto err; - if (!BN_mod_mul(tmp3, u, x, N, bn_ctx)) goto err; if (!BN_mod_add(tmp2, a, tmp3, N, bn_ctx)) diff --git a/crypto/srp/srp_vfy.c b/crypto/srp/srp_vfy.c index 075c9ed283..79db92a290 100644 --- a/crypto/srp/srp_vfy.c +++ b/crypto/srp/srp_vfy.c @@ -253,8 +253,8 @@ SRP_VBASE *SRP_VBASE_new(char *seed_key) if (vb == NULL) return NULL; - if (!(vb->users_pwd = sk_SRP_user_pwd_new_null()) || - !(vb->gN_cache = sk_SRP_gN_cache_new_null())) { + if ((vb->users_pwd = sk_SRP_user_pwd_new_null()) == NULL + || (vb->gN_cache = sk_SRP_gN_cache_new_null()) == NULL) { OPENSSL_free(vb); return NULL; } @@ -394,10 +394,11 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file) if ((gN = OPENSSL_malloc(sizeof(*gN))) == NULL) goto err; - if (!(gN->id = BUF_strdup(pp[DB_srpid])) - || !(gN->N = - SRP_gN_place_bn(vb->gN_cache, pp[DB_srpverifier])) - || !(gN->g = SRP_gN_place_bn(vb->gN_cache, pp[DB_srpsalt])) + if ((gN->id = BUF_strdup(pp[DB_srpid])) == NULL + || (gN->N = SRP_gN_place_bn(vb->gN_cache, pp[DB_srpverifier])) + == NULL + || (gN->g = SRP_gN_place_bn(vb->gN_cache, pp[DB_srpsalt])) + == NULL || sk_SRP_gN_insert(SRP_gN_tab, gN, 0) == 0) goto err; @@ -533,10 +534,10 @@ char *SRP_create_verifier(const char *user, const char *pass, char **salt, goto err; if (N) { - if (!(len = t_fromb64(tmp, N))) + if ((len = t_fromb64(tmp, N)) == 0) goto err; N_bn = BN_bin2bn(tmp, len, NULL); - if (!(len = t_fromb64(tmp, g))) + if ((len = t_fromb64(tmp, g)) == 0) goto err; g_bn = BN_bin2bn(tmp, len, NULL); defgNid = "*"; @@ -555,7 +556,7 @@ char *SRP_create_verifier(const char *user, const char *pass, char **salt, s = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL); } else { - if (!(len = t_fromb64(tmp2, *salt))) + if ((len = t_fromb64(tmp2, *salt)) == 0) goto err; s = BN_bin2bn(tmp2, len, NULL); } diff --git a/crypto/ts/ts_conf.c b/crypto/ts/ts_conf.c index 2b85660209..121b60ba18 100644 --- a/crypto/ts/ts_conf.c +++ b/crypto/ts/ts_conf.c @@ -114,11 +114,11 @@ STACK_OF(X509) *TS_CONF_load_certs(const char *file) STACK_OF(X509_INFO) *allcerts = NULL; int i; - if (!(certs = BIO_new_file(file, "r"))) + if ((certs = BIO_new_file(file, "r")) == NULL) goto end; - - if (!(othercerts = sk_X509_new_null())) + if ((othercerts = sk_X509_new_null()) == NULL) goto end; + allcerts = PEM_X509_INFO_read_bio(certs, NULL, NULL, NULL); for (i = 0; i < sk_X509_INFO_num(allcerts); i++) { X509_INFO *xi = sk_X509_INFO_value(allcerts, i); @@ -140,7 +140,7 @@ EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass) BIO *key = NULL; EVP_PKEY *pkey = NULL; - if (!(key = BIO_new_file(file, "r"))) + if ((key = BIO_new_file(file, "r")) == NULL) goto end; pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, (char *)pass); end: @@ -195,7 +195,7 @@ int TS_CONF_set_crypto_device(CONF *conf, const char *section, { int ret = 0; - if (!device) + if (device == NULL) device = NCONF_get_string(conf, section, ENV_CRYPTO_DEVICE); if (device && !TS_CONF_set_default_engine(device)) { @@ -216,8 +216,9 @@ int TS_CONF_set_default_engine(const char *name) if (strcmp(name, "builtin") == 0) return 1; - if (!(e = ENGINE_by_id(name))) + if ((e = ENGINE_by_id(name)) == NULL) goto err; + /* Enable the use of the NCipher HSM for forked children. */ if (strcmp(name, "chil") == 0) ENGINE_ctrl(e, ENGINE_CTRL_CHIL_SET_FORKCHECK, 1, 0, 0); @@ -241,13 +242,15 @@ int TS_CONF_set_signer_cert(CONF *conf, const char *section, { int ret = 0; X509 *cert_obj = NULL; - if (!cert) + + if (cert == NULL) { cert = NCONF_get_string(conf, section, ENV_SIGNER_CERT); - if (!cert) { - TS_CONF_lookup_fail(section, ENV_SIGNER_CERT); - goto err; + if (cert == NULL) { + TS_CONF_lookup_fail(section, ENV_SIGNER_CERT); + goto err; + } } - if (!(cert_obj = TS_CONF_load_cert(cert))) + if ((cert_obj = TS_CONF_load_cert(cert)) == NULL) goto err; if (!TS_RESP_CTX_set_signer_cert(ctx, cert_obj)) goto err; @@ -263,12 +266,13 @@ int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs, { int ret = 0; STACK_OF(X509) *certs_obj = NULL; - if (!certs) - certs = NCONF_get_string(conf, section, ENV_CERTS); - /* Certificate chain is optional. */ - if (!certs) - goto end; - if (!(certs_obj = TS_CONF_load_certs(certs))) + + if (certs == NULL) { + /* Certificate chain is optional. */ + if ((certs = NCONF_get_string(conf, section, ENV_CERTS)) == NULL) + goto end; + } + if ((certs_obj = TS_CONF_load_certs(certs)) == NULL) goto err; if (!TS_RESP_CTX_set_certs(ctx, certs_obj)) goto err; @@ -291,7 +295,7 @@ int TS_CONF_set_signer_key(CONF *conf, const char *section, TS_CONF_lookup_fail(section, ENV_SIGNER_KEY); goto err; } - if (!(key_obj = TS_CONF_load_key(key, pass))) + if ((key_obj = TS_CONF_load_key(key, pass)) == NULL) goto err; if (!TS_RESP_CTX_set_signer_key(ctx, key_obj)) goto err; @@ -313,7 +317,7 @@ int TS_CONF_set_def_policy(CONF *conf, const char *section, TS_CONF_lookup_fail(section, ENV_DEFAULT_POLICY); goto err; } - if (!(policy_obj = OBJ_txt2obj(policy, 0))) { + if ((policy_obj = OBJ_txt2obj(policy, 0)) == NULL) { TS_CONF_invalid(section, ENV_DEFAULT_POLICY); goto err; } @@ -331,10 +335,10 @@ int TS_CONF_set_policies(CONF *conf, const char *section, TS_RESP_CTX *ctx) int ret = 0; int i; STACK_OF(CONF_VALUE) *list = NULL; - char *policies = NCONF_get_string(conf, section, - ENV_OTHER_POLICIES); + char *policies = NCONF_get_string(conf, section, ENV_OTHER_POLICIES); + /* If no other policy is specified, that's fine. */ - if (policies && !(list = X509V3_parse_list(policies))) { + if (policies && (list = X509V3_parse_list(policies)) == NULL) { TS_CONF_invalid(section, ENV_OTHER_POLICIES); goto err; } @@ -342,7 +346,8 @@ int TS_CONF_set_policies(CONF *conf, const char *section, TS_RESP_CTX *ctx) CONF_VALUE *val = sk_CONF_VALUE_value(list, i); const char *extval = val->value ? val->value : val->name; ASN1_OBJECT *objtmp; - if (!(objtmp = OBJ_txt2obj(extval, 0))) { + + if ((objtmp = OBJ_txt2obj(extval, 0)) == NULL) { TS_CONF_invalid(section, ENV_OTHER_POLICIES); goto err; } @@ -363,11 +368,12 @@ int TS_CONF_set_digests(CONF *conf, const char *section, TS_RESP_CTX *ctx) int i; STACK_OF(CONF_VALUE) *list = NULL; char *digests = NCONF_get_string(conf, section, ENV_DIGESTS); - if (!digests) { + + if (digests == NULL) { TS_CONF_lookup_fail(section, ENV_DIGESTS); goto err; } - if (!(list = X509V3_parse_list(digests))) { + if ((list = X509V3_parse_list(digests)) == NULL) { TS_CONF_invalid(section, ENV_DIGESTS); goto err; } @@ -379,7 +385,8 @@ int TS_CONF_set_digests(CONF *conf, const char *section, TS_RESP_CTX *ctx) CONF_VALUE *val = sk_CONF_VALUE_value(list, i); const char *extval = val->value ? val->value : val->name; const EVP_MD *md; - if (!(md = EVP_get_digestbyname(extval))) { + + if ((md = EVP_get_digestbyname(extval)) == NULL) { TS_CONF_invalid(section, ENV_DIGESTS); goto err; } @@ -401,7 +408,7 @@ int TS_CONF_set_accuracy(CONF *conf, const char *section, TS_RESP_CTX *ctx) STACK_OF(CONF_VALUE) *list = NULL; char *accuracy = NCONF_get_string(conf, section, ENV_ACCURACY); - if (accuracy && !(list = X509V3_parse_list(accuracy))) { + if (accuracy && (list = X509V3_parse_list(accuracy)) == NULL) { TS_CONF_invalid(section, ENV_ACCURACY); goto err; } diff --git a/crypto/ts/ts_rsp_sign.c b/crypto/ts/ts_rsp_sign.c index 077d03da2c..b16cf91d96 100644 --- a/crypto/ts/ts_rsp_sign.c +++ b/crypto/ts/ts_rsp_sign.c @@ -169,7 +169,7 @@ TS_RESP_CTX *TS_RESP_CTX_new() { TS_RESP_CTX *ctx; - if (!(ctx = OPENSSL_malloc(sizeof(*ctx)))) { + if ((ctx = OPENSSL_malloc(sizeof(*ctx))) == NULL) { TSerr(TS_F_TS_RESP_CTX_NEW, ERR_R_MALLOC_FAILURE); return NULL; } @@ -225,7 +225,7 @@ int TS_RESP_CTX_set_signer_key(TS_RESP_CTX *ctx, EVP_PKEY *key) int TS_RESP_CTX_set_def_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *def_policy) { ASN1_OBJECT_free(ctx->default_policy); - if (!(ctx->default_policy = OBJ_dup(def_policy))) + if ((ctx->default_policy = OBJ_dup(def_policy)) == NULL) goto err; return 1; err: @@ -240,7 +240,7 @@ int TS_RESP_CTX_set_certs(TS_RESP_CTX *ctx, STACK_OF(X509) *certs) ctx->certs = NULL; if (!certs) return 1; - if (!(ctx->certs = X509_chain_up_ref(certs))) { + if ((ctx->certs = X509_chain_up_ref(certs)) == NULL) { TSerr(TS_F_TS_RESP_CTX_SET_CERTS, ERR_R_MALLOC_FAILURE); return 0; } @@ -253,9 +253,10 @@ int TS_RESP_CTX_add_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *policy) ASN1_OBJECT *copy = NULL; /* Create new policy stack if necessary. */ - if (!ctx->policies && !(ctx->policies = sk_ASN1_OBJECT_new_null())) + if (ctx->policies == NULL + && (ctx->policies = sk_ASN1_OBJECT_new_null()) == NULL) goto err; - if (!(copy = OBJ_dup(policy))) + if ((copy = OBJ_dup(policy)) == NULL) goto err; if (!sk_ASN1_OBJECT_push(ctx->policies, copy)) goto err; @@ -270,7 +271,8 @@ int TS_RESP_CTX_add_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *policy) int TS_RESP_CTX_add_md(TS_RESP_CTX *ctx, const EVP_MD *md) { /* Create new md stack if necessary. */ - if (!ctx->mds && !(ctx->mds = sk_EVP_MD_new_null())) + if (ctx->mds == NULL + && (ctx->mds = sk_EVP_MD_new_null()) == NULL) goto err; /* Add the shared md, no copy needed. */ if (!sk_EVP_MD_push(ctx->mds, (EVP_MD *)md)) @@ -295,14 +297,17 @@ int TS_RESP_CTX_set_accuracy(TS_RESP_CTX *ctx, { TS_RESP_CTX_accuracy_free(ctx); - if (secs && (!(ctx->seconds = ASN1_INTEGER_new()) - || !ASN1_INTEGER_set(ctx->seconds, secs))) + if (secs + && ((ctx->seconds = ASN1_INTEGER_new()) == NULL + || !ASN1_INTEGER_set(ctx->seconds, secs))) goto err; - if (millis && (!(ctx->millis = ASN1_INTEGER_new()) - || !ASN1_INTEGER_set(ctx->millis, millis))) + if (millis + && ((ctx->millis = ASN1_INTEGER_new()) == NULL + || !ASN1_INTEGER_set(ctx->millis, millis))) goto err; - if (micros && (!(ctx->micros = ASN1_INTEGER_new()) - || !ASN1_INTEGER_set(ctx->micros, micros))) + if (micros + && ((ctx->micros = ASN1_INTEGER_new()) == NULL + || !ASN1_INTEGER_set(ctx->micros, micros))) goto err; return 1; @@ -343,15 +348,16 @@ int TS_RESP_CTX_set_status_info(TS_RESP_CTX *ctx, ASN1_UTF8STRING *utf8_text = NULL; int ret = 0; - if (!(si = TS_STATUS_INFO_new())) + if ((si = TS_STATUS_INFO_new()) == NULL) goto err; if (!ASN1_INTEGER_set(si->status, status)) goto err; if (text) { - if (!(utf8_text = ASN1_UTF8STRING_new()) + if ((utf8_text = ASN1_UTF8STRING_new()) == NULL || !ASN1_STRING_set(utf8_text, text, strlen(text))) goto err; - if (!si->text && !(si->text = sk_ASN1_UTF8STRING_new_null())) + if (si->text == NULL + && (si->text = sk_ASN1_UTF8STRING_new_null()) == NULL) goto err; if (!sk_ASN1_UTF8STRING_push(si->text, utf8_text)) goto err; @@ -384,7 +390,8 @@ int TS_RESP_CTX_set_status_info_cond(TS_RESP_CTX *ctx, int TS_RESP_CTX_add_failure_info(TS_RESP_CTX *ctx, int failure) { TS_STATUS_INFO *si = TS_RESP_get_status_info(ctx->response); - if (!si->failure_info && !(si->failure_info = ASN1_BIT_STRING_new())) + if (si->failure_info == NULL + && (si->failure_info = ASN1_BIT_STRING_new()) == NULL) goto err; if (!ASN1_BIT_STRING_set_bit(si->failure_info, failure, 1)) goto err; @@ -423,13 +430,13 @@ TS_RESP *TS_RESP_create_response(TS_RESP_CTX *ctx, BIO *req_bio) TS_RESP_CTX_init(ctx); /* Creating the response object. */ - if (!(ctx->response = TS_RESP_new())) { + if ((ctx->response = TS_RESP_new()) == NULL) { TSerr(TS_F_TS_RESP_CREATE_RESPONSE, ERR_R_MALLOC_FAILURE); goto end; } /* Parsing DER request. */ - if (!(ctx->request = d2i_TS_REQ_bio(req_bio, NULL))) { + if ((ctx->request = d2i_TS_REQ_bio(req_bio, NULL)) == NULL) { TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION, "Bad request format or " "system error."); TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_DATA_FORMAT); @@ -445,11 +452,11 @@ TS_RESP *TS_RESP_create_response(TS_RESP_CTX *ctx, BIO *req_bio) goto end; /* Checking acceptable policies. */ - if (!(policy = TS_RESP_get_policy(ctx))) + if ((policy = TS_RESP_get_policy(ctx)) == NULL) goto end; /* Creating the TS_TST_INFO object. */ - if (!(ctx->tst_info = TS_RESP_create_tst_info(ctx, policy))) + if ((ctx->tst_info = TS_RESP_create_tst_info(ctx, policy)) == NULL) goto end; /* Processing extensions. */ @@ -602,7 +609,7 @@ static TS_TST_INFO *TS_RESP_create_tst_info(TS_RESP_CTX *ctx, const ASN1_INTEGER *nonce; GENERAL_NAME *tsa_name = NULL; - if (!(tst_info = TS_TST_INFO_new())) + if ((tst_info = TS_TST_INFO_new()) == NULL) goto end; if (!TS_TST_INFO_set_version(tst_info, 1)) goto end; @@ -610,19 +617,19 @@ static TS_TST_INFO *TS_RESP_create_tst_info(TS_RESP_CTX *ctx, goto end; if (!TS_TST_INFO_set_msg_imprint(tst_info, ctx->request->msg_imprint)) goto end; - if (!(serial = (*ctx->serial_cb) (ctx, ctx->serial_cb_data)) + if ((serial = ctx->serial_cb(ctx, ctx->serial_cb_data)) == NULL || !TS_TST_INFO_set_serial(tst_info, serial)) goto end; - if (!(*ctx->time_cb) (ctx, ctx->time_cb_data, &sec, &usec) - || !(asn1_time = TS_RESP_set_genTime_with_precision(NULL, - sec, usec, - ctx->clock_precision_digits)) + if (!ctx->time_cb(ctx, ctx->time_cb_data, &sec, &usec) + || (asn1_time = + TS_RESP_set_genTime_with_precision(NULL, sec, usec, + ctx->clock_precision_digits)) == NULL || !TS_TST_INFO_set_time(tst_info, asn1_time)) goto end; /* Setting accuracy if needed. */ if ((ctx->seconds || ctx->millis || ctx->micros) - && !(accuracy = TS_ACCURACY_new())) + && (accuracy = TS_ACCURACY_new()) == NULL) goto end; if (ctx->seconds && !TS_ACCURACY_set_seconds(accuracy, ctx->seconds)) @@ -646,7 +653,7 @@ static TS_TST_INFO *TS_RESP_create_tst_info(TS_RESP_CTX *ctx, /* Setting TSA name to subject of signer certificate. */ if (ctx->flags & TS_TSA_NAME) { - if (!(tsa_name = GENERAL_NAME_new())) + if ((tsa_name = GENERAL_NAME_new()) == NULL) goto end; tsa_name->type = GEN_DIRNAME; tsa_name->d.dirn = @@ -715,7 +722,7 @@ static int TS_RESP_sign(TS_RESP_CTX *ctx) } /* Create a new PKCS7 signed object. */ - if (!(p7 = PKCS7_new())) { + if ((p7 = PKCS7_new()) == NULL) { TSerr(TS_F_TS_RESP_SIGN, ERR_R_MALLOC_FAILURE); goto err; } @@ -738,8 +745,8 @@ static int TS_RESP_sign(TS_RESP_CTX *ctx) } /* Add a new signer info. */ - if (!(si = PKCS7_add_signature(p7, ctx->signer_cert, - ctx->signer_key, EVP_sha1()))) { + if ((si = PKCS7_add_signature(p7, ctx->signer_cert, + ctx->signer_key, EVP_sha1())) == NULL) { TSerr(TS_F_TS_RESP_SIGN, TS_R_PKCS7_ADD_SIGNATURE_ERROR); goto err; } @@ -757,7 +764,7 @@ static int TS_RESP_sign(TS_RESP_CTX *ctx) * certificate id and optionally the certificate chain. */ certs = ctx->flags & TS_ESS_CERT_ID_CHAIN ? ctx->certs : NULL; - if (!(sc = ESS_SIGNING_CERT_new_init(ctx->signer_cert, certs))) + if ((sc = ESS_SIGNING_CERT_new_init(ctx->signer_cert, certs)) == NULL) goto err; /* Add SigningCertificate signed attribute to the signer info. */ @@ -771,7 +778,7 @@ static int TS_RESP_sign(TS_RESP_CTX *ctx) goto err; /* Add the DER encoded tst_info to the PKCS7 structure. */ - if (!(p7bio = PKCS7_dataInit(p7, NULL))) { + if ((p7bio = PKCS7_dataInit(p7, NULL)) == NULL) { TSerr(TS_F_TS_RESP_SIGN, ERR_R_MALLOC_FAILURE); goto err; } @@ -813,19 +820,20 @@ static ESS_SIGNING_CERT *ESS_SIGNING_CERT_new_init(X509 *signcert, int i; /* Creating the ESS_CERT_ID stack. */ - if (!(sc = ESS_SIGNING_CERT_new())) + if ((sc = ESS_SIGNING_CERT_new()) == NULL) goto err; - if (!sc->cert_ids && !(sc->cert_ids = sk_ESS_CERT_ID_new_null())) + if (sc->cert_ids == NULL + && (sc->cert_ids = sk_ESS_CERT_ID_new_null()) == NULL) goto err; /* Adding the signing certificate id. */ - if (!(cid = ESS_CERT_ID_new_init(signcert, 0)) + if ((cid = ESS_CERT_ID_new_init(signcert, 0)) == NULL || !sk_ESS_CERT_ID_push(sc->cert_ids, cid)) goto err; /* Adding the certificate chain ids. */ for (i = 0; i < sk_X509_num(certs); ++i) { X509 *cert = sk_X509_value(certs, i); - if (!(cid = ESS_CERT_ID_new_init(cert, 1)) + if ((cid = ESS_CERT_ID_new_init(cert, 1)) == NULL || !sk_ESS_CERT_ID_push(sc->cert_ids, cid)) goto err; } @@ -845,7 +853,7 @@ static ESS_CERT_ID *ESS_CERT_ID_new_init(X509 *cert, int issuer_needed) /* Recompute SHA1 hash of certificate if necessary (side effect). */ X509_check_purpose(cert, -1, 0); - if (!(cid = ESS_CERT_ID_new())) + if ((cid = ESS_CERT_ID_new()) == NULL) goto err; if (!ASN1_OCTET_STRING_set(cid->hash, cert->sha1_hash, sizeof(cert->sha1_hash))) @@ -854,14 +862,14 @@ static ESS_CERT_ID *ESS_CERT_ID_new_init(X509 *cert, int issuer_needed) /* Setting the issuer/serial if requested. */ if (issuer_needed) { /* Creating issuer/serial structure. */ - if (!cid->issuer_serial - && !(cid->issuer_serial = ESS_ISSUER_SERIAL_new())) + if (cid->issuer_serial == NULL + && (cid->issuer_serial = ESS_ISSUER_SERIAL_new()) == NULL) goto err; /* Creating general name from the certificate issuer. */ - if (!(name = GENERAL_NAME_new())) + if ((name = GENERAL_NAME_new()) == NULL) goto err; name->type = GEN_DIRNAME; - if (!(name->d.dirn = X509_NAME_dup(cert->cert_info->issuer))) + if ((name->d.dirn = X509_NAME_dup(cert->cert_info->issuer)) == NULL) goto err; if (!sk_GENERAL_NAME_push(cid->issuer_serial->issuer, name)) goto err; @@ -887,12 +895,12 @@ static int TS_TST_INFO_content_new(PKCS7 *p7) ASN1_OCTET_STRING *octet_string = NULL; /* Create new encapsulated NID_id_smime_ct_TSTInfo content. */ - if (!(ret = PKCS7_new())) + if ((ret = PKCS7_new()) == NULL) goto err; - if (!(ret->d.other = ASN1_TYPE_new())) + if ((ret->d.other = ASN1_TYPE_new()) == NULL) goto err; ret->type = OBJ_nid2obj(NID_id_smime_ct_TSTInfo); - if (!(octet_string = ASN1_OCTET_STRING_new())) + if ((octet_string = ASN1_OCTET_STRING_new()) == NULL) goto err; ASN1_TYPE_set(ret->d.other, V_ASN1_OCTET_STRING, octet_string); octet_string = NULL; @@ -915,13 +923,13 @@ static int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc) int len; len = i2d_ESS_SIGNING_CERT(sc, NULL); - if (!(pp = OPENSSL_malloc(len))) { + if ((pp = OPENSSL_malloc(len)) == NULL) { TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE); goto err; } p = pp; i2d_ESS_SIGNING_CERT(sc, &p); - if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len)) { + if ((seq = ASN1_STRING_new()) == NULL || !ASN1_STRING_set(seq, pp, len)) { TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE); goto err; } @@ -950,7 +958,7 @@ static ASN1_GENERALIZEDTIME if (precision > TS_MAX_CLOCK_PRECISION_DIGITS) goto err; - if (!(tm = gmtime(&time_sec))) + if ((tm = gmtime(&time_sec)) == NULL) goto err; /* @@ -1001,7 +1009,8 @@ static ASN1_GENERALIZEDTIME *p++ = '\0'; /* Now call OpenSSL to check and set our genTime value */ - if (!asn1_time && !(asn1_time = ASN1_GENERALIZEDTIME_new())) + if (asn1_time == NULL + && (asn1_time = ASN1_GENERALIZEDTIME_new()) == NULL) goto err; if (!ASN1_GENERALIZEDTIME_set_string(asn1_time, genTime_str)) { ASN1_GENERALIZEDTIME_free(asn1_time); diff --git a/crypto/ts/ts_rsp_verify.c b/crypto/ts/ts_rsp_verify.c index 8381d4148b..939c65f8f0 100644 --- a/crypto/ts/ts_rsp_verify.c +++ b/crypto/ts/ts_rsp_verify.c @@ -511,7 +511,7 @@ static int TS_check_status_info(TS_RESP *response) /* Set the embedded_status_text to the returned description. */ if (sk_ASN1_UTF8STRING_num(info->text) > 0 - && !(embedded_status_text = TS_get_status_text(info->text))) + && (embedded_status_text = TS_get_status_text(info->text)) == NULL) return 0; /* Filling in failure_text with the failure information. */ @@ -558,7 +558,7 @@ static char *TS_get_status_text(STACK_OF(ASN1_UTF8STRING) *text) length += 1; /* separator character */ } /* Allocate memory (closing '\0' included). */ - if (!(result = OPENSSL_malloc(length))) { + if ((result = OPENSSL_malloc(length)) == NULL) { TSerr(TS_F_TS_GET_STATUS_TEXT, ERR_R_MALLOC_FAILURE); return NULL; } @@ -604,11 +604,11 @@ static int TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info, *imprint = NULL; /* Return the MD algorithm of the response. */ - if (!(*md_alg = X509_ALGOR_dup(md_alg_resp))) + if ((*md_alg = X509_ALGOR_dup(md_alg_resp)) == NULL) goto err; /* Getting the MD object. */ - if (!(md = EVP_get_digestbyobj((*md_alg)->algorithm))) { + if ((md = EVP_get_digestbyobj((*md_alg)->algorithm)) == NULL) { TSerr(TS_F_TS_COMPUTE_IMPRINT, TS_R_UNSUPPORTED_MD_ALGORITHM); goto err; } @@ -618,7 +618,7 @@ static int TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info, if (length < 0) goto err; *imprint_len = length; - if (!(*imprint = OPENSSL_malloc(*imprint_len))) { + if ((*imprint = OPENSSL_malloc(*imprint_len)) == NULL) { TSerr(TS_F_TS_COMPUTE_IMPRINT, ERR_R_MALLOC_FAILURE); goto err; } @@ -708,15 +708,16 @@ static int TS_check_signer_name(GENERAL_NAME *tsa_name, X509 *signer) /* Check all the alternative names. */ gen_names = X509_get_ext_d2i(signer, NID_subject_alt_name, NULL, &idx); - while (gen_names != NULL - && !(found = TS_find_name(gen_names, tsa_name) >= 0)) { + while (gen_names != NULL) { + found = TS_find_name(gen_names, tsa_name) >= 0; + if (found) + break; /* * Get the next subject alternative name, although there should be no * more than one. */ GENERAL_NAMES_free(gen_names); - gen_names = X509_get_ext_d2i(signer, NID_subject_alt_name, - NULL, &idx); + gen_names = X509_get_ext_d2i(signer, NID_subject_alt_name, NULL, &idx); } GENERAL_NAMES_free(gen_names); diff --git a/crypto/ts/ts_verify_ctx.c b/crypto/ts/ts_verify_ctx.c index 75bf2dfa42..3c15e66954 100644 --- a/crypto/ts/ts_verify_ctx.c +++ b/crypto/ts/ts_verify_ctx.c @@ -121,7 +121,7 @@ TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx) OPENSSL_assert(req != NULL); if (ret) TS_VERIFY_CTX_cleanup(ret); - else if (!(ret = TS_VERIFY_CTX_new())) + else if ((ret = TS_VERIFY_CTX_new()) == NULL) return NULL; /* Setting flags. */ @@ -129,7 +129,7 @@ TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx) /* Setting policy. */ if ((policy = TS_REQ_get_policy_id(req)) != NULL) { - if (!(ret->policy = OBJ_dup(policy))) + if ((ret->policy = OBJ_dup(policy)) == NULL) goto err; } else ret->flags &= ~TS_VFY_POLICY; @@ -137,17 +137,17 @@ TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx) /* Setting md_alg, imprint and imprint_len. */ imprint = TS_REQ_get_msg_imprint(req); md_alg = TS_MSG_IMPRINT_get_algo(imprint); - if (!(ret->md_alg = X509_ALGOR_dup(md_alg))) + if ((ret->md_alg = X509_ALGOR_dup(md_alg)) == NULL) goto err; msg = TS_MSG_IMPRINT_get_msg(imprint); ret->imprint_len = ASN1_STRING_length(msg); - if (!(ret->imprint = OPENSSL_malloc(ret->imprint_len))) + if ((ret->imprint = OPENSSL_malloc(ret->imprint_len)) == NULL) goto err; memcpy(ret->imprint, ASN1_STRING_data(msg), ret->imprint_len); /* Setting nonce. */ if ((nonce = TS_REQ_get_nonce(req)) != NULL) { - if (!(ret->nonce = ASN1_INTEGER_dup(nonce))) + if ((ret->nonce = ASN1_INTEGER_dup(nonce)) == NULL) goto err; } else ret->flags &= ~TS_VFY_NONCE; diff --git a/crypto/txt_db/txt_db.c b/crypto/txt_db/txt_db.c index 54c85d2245..5134855362 100644 --- a/crypto/txt_db/txt_db.c +++ b/crypto/txt_db/txt_db.c @@ -123,7 +123,7 @@ TXT_DB *TXT_DB_read(BIO *in, int num) continue; else { buf->data[offset - 1] = '\0'; /* blat the '\n' */ - if (!(p = OPENSSL_malloc(add + offset))) + if ((p = OPENSSL_malloc(add + offset)) == NULL) goto err; offset = 0; } diff --git a/crypto/x509/x509_att.c b/crypto/x509/x509_att.c index df49b0b17f..67f6b8f3cc 100644 --- a/crypto/x509/x509_att.c +++ b/crypto/x509/x509_att.c @@ -309,7 +309,7 @@ int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, } atype = stmp->type; } else if (len != -1) { - if (!(stmp = ASN1_STRING_type_new(attrtype))) + if ((stmp = ASN1_STRING_type_new(attrtype)) == NULL) goto err; if (!ASN1_STRING_set(stmp, data, len)) goto err; @@ -322,7 +322,7 @@ int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, */ if (attrtype == 0) return 1; - if (!(ttmp = ASN1_TYPE_new())) + if ((ttmp = ASN1_TYPE_new()) == NULL) goto err; if ((len == -1) && !(attrtype & MBSTRING_FLAG)) { if (!ASN1_TYPE_set1(ttmp, attrtype, data)) diff --git a/crypto/x509/x509_trs.c b/crypto/x509/x509_trs.c index 4207f422c2..7a165424d8 100644 --- a/crypto/x509/x509_trs.c +++ b/crypto/x509/x509_trs.c @@ -188,7 +188,7 @@ int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), idx = X509_TRUST_get_by_id(id); /* Need a new entry */ if (idx == -1) { - if (!(trtmp = OPENSSL_malloc(sizeof(*trtmp)))) { + if ((trtmp = OPENSSL_malloc(sizeof(*trtmp))) == NULL) { X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); return 0; } @@ -200,7 +200,7 @@ int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), if (trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_free(trtmp->name); /* dup supplied name */ - if (!(trtmp->name = BUF_strdup(name))) { + if ((trtmp->name = BUF_strdup(name)) == NULL) { X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); return 0; } @@ -216,7 +216,8 @@ int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), /* If its a new entry manage the dynamic table */ if (idx == -1) { - if (!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) { + if (trtable == NULL + && (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) { X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/x509/x509spki.c b/crypto/x509/x509spki.c index fb46d4e3af..482741ae56 100644 --- a/crypto/x509/x509spki.c +++ b/crypto/x509/x509spki.c @@ -85,7 +85,7 @@ NETSCAPE_SPKI *NETSCAPE_SPKI_b64_decode(const char *str, int len) NETSCAPE_SPKI *spki; if (len <= 0) len = strlen(str); - if (!(spki_der = OPENSSL_malloc(len + 1))) { + if ((spki_der = OPENSSL_malloc(len + 1)) == NULL) { X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/x509v3/pcy_tree.c b/crypto/x509v3/pcy_tree.c index 6b0167b2e3..7b54e5c47c 100644 --- a/crypto/x509v3/pcy_tree.c +++ b/crypto/x509v3/pcy_tree.c @@ -532,7 +532,7 @@ static int tree_calculate_authority_set(X509_POLICY_TREE *tree, * If no anyPolicy node on this this level it can't appear on lower * levels so end search. */ - if (!(anyptr = curr->anyPolicy)) + if ((anyptr = curr->anyPolicy) == NULL) break; curr++; for (j = 0; j < sk_X509_POLICY_NODE_num(curr->nodes); j++) { diff --git a/crypto/x509v3/v3_akey.c b/crypto/x509v3/v3_akey.c index 652c90483e..61bc7b35bd 100644 --- a/crypto/x509v3/v3_akey.c +++ b/crypto/x509v3/v3_akey.c @@ -177,12 +177,12 @@ static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, } } - if (!(akeyid = AUTHORITY_KEYID_new())) + if ((akeyid = AUTHORITY_KEYID_new()) == NULL) goto err; if (isname) { - if (!(gens = sk_GENERAL_NAME_new_null()) - || !(gen = GENERAL_NAME_new()) + if ((gens = sk_GENERAL_NAME_new_null()) == NULL + || (gen = GENERAL_NAME_new()) == NULL || !sk_GENERAL_NAME_push(gens, gen)) { X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, ERR_R_MALLOC_FAILURE); goto err; diff --git a/crypto/x509v3/v3_alt.c b/crypto/x509v3/v3_alt.c index c0c63a9878..20f94903af 100644 --- a/crypto/x509v3/v3_alt.c +++ b/crypto/x509v3/v3_alt.c @@ -243,7 +243,8 @@ static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method, GENERAL_NAMES *gens = NULL; CONF_VALUE *cnf; int i; - if (!(gens = sk_GENERAL_NAME_new_null())) { + + if ((gens = sk_GENERAL_NAME_new_null()) == NULL) { X509V3err(X509V3_F_V2I_ISSUER_ALT, ERR_R_MALLOC_FAILURE); return NULL; } @@ -255,7 +256,7 @@ static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method, goto err; } else { GENERAL_NAME *gen; - if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) + if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL) goto err; sk_GENERAL_NAME_push(gens, gen); } @@ -274,6 +275,7 @@ static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens) GENERAL_NAME *gen; X509_EXTENSION *ext; int i; + if (ctx && (ctx->flags == CTX_TEST)) return 1; if (!ctx || !ctx->issuer_cert) { @@ -283,8 +285,8 @@ static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens) i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1); if (i < 0) return 1; - if (!(ext = X509_get_ext(ctx->issuer_cert, i)) || - !(ialt = X509V3_EXT_d2i(ext))) { + if ((ext = X509_get_ext(ctx->issuer_cert, i)) == NULL + || (ialt = X509V3_EXT_d2i(ext)) == NULL) { X509V3err(X509V3_F_COPY_ISSUER, X509V3_R_ISSUER_DECODE_ERROR); goto err; } @@ -312,7 +314,8 @@ static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method, GENERAL_NAMES *gens = NULL; CONF_VALUE *cnf; int i; - if (!(gens = sk_GENERAL_NAME_new_null())) { + + if ((gens = sk_GENERAL_NAME_new_null()) == NULL) { X509V3err(X509V3_F_V2I_SUBJECT_ALT, ERR_R_MALLOC_FAILURE); return NULL; } @@ -328,7 +331,7 @@ static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method, goto err; } else { GENERAL_NAME *gen; - if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) + if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL) goto err; sk_GENERAL_NAME_push(gens, gen); } @@ -373,7 +376,7 @@ static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p) X509_NAME_ENTRY_free(ne); i--; } - if (!email || !(gen = GENERAL_NAME_new())) { + if (email == NULL || (gen = GENERAL_NAME_new()) == NULL) { X509V3err(X509V3_F_COPY_EMAIL, ERR_R_MALLOC_FAILURE); goto err; } @@ -403,13 +406,14 @@ GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, GENERAL_NAMES *gens = NULL; CONF_VALUE *cnf; int i; - if (!(gens = sk_GENERAL_NAME_new_null())) { + + if ((gens = sk_GENERAL_NAME_new_null()) == NULL) { X509V3err(X509V3_F_V2I_GENERAL_NAMES, ERR_R_MALLOC_FAILURE); return NULL; } for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { cnf = sk_CONF_VALUE_value(nval, i); - if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) + if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL) goto err; sk_GENERAL_NAME_push(gens, gen); } @@ -458,7 +462,7 @@ GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out, case GEN_RID: { ASN1_OBJECT *obj; - if (!(obj = OBJ_txt2obj(value, 0))) { + if ((obj = OBJ_txt2obj(value, 0)) == NULL) { X509V3err(X509V3_F_A2I_GENERAL_NAME, X509V3_R_BAD_OBJECT); ERR_add_error_data(2, "value=", value); goto err; @@ -498,7 +502,7 @@ GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out, } if (is_string) { - if (!(gen->d.ia5 = ASN1_IA5STRING_new()) || + if ((gen->d.ia5 = ASN1_IA5STRING_new()) == NULL || !ASN1_STRING_set(gen->d.ia5, (unsigned char *)value, strlen(value))) { X509V3err(X509V3_F_A2I_GENERAL_NAME, ERR_R_MALLOC_FAILURE); @@ -560,16 +564,17 @@ static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx) { char *objtmp = NULL, *p; int objlen; - if (!(p = strchr(value, ';'))) + + if ((p = strchr(value, ';')) == NULL) return 0; - if (!(gen->d.otherName = OTHERNAME_new())) + if ((gen->d.otherName = OTHERNAME_new()) == NULL) return 0; /* * Free this up because we will overwrite it. no need to free type_id * because it is static */ ASN1_TYPE_free(gen->d.otherName->value); - if (!(gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx))) + if ((gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx)) == NULL) return 0; objlen = p - value; objtmp = OPENSSL_malloc(objlen + 1); @@ -588,8 +593,9 @@ static int do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx) { int ret = 0; STACK_OF(CONF_VALUE) *sk = NULL; - X509_NAME *nm = NULL; - if (!(nm = X509_NAME_new())) + X509_NAME *nm; + + if ((nm = X509_NAME_new()) == NULL) goto err; sk = X509V3_get_section(ctx, value); if (!sk) { diff --git a/crypto/x509v3/v3_bcons.c b/crypto/x509v3/v3_bcons.c index 97bc079c0e..3b89efba34 100644 --- a/crypto/x509v3/v3_bcons.c +++ b/crypto/x509v3/v3_bcons.c @@ -107,7 +107,8 @@ static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons = NULL; CONF_VALUE *val; int i; - if (!(bcons = BASIC_CONSTRAINTS_new())) { + + if ((bcons = BASIC_CONSTRAINTS_new()) == NULL) { X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/x509v3/v3_bitst.c b/crypto/x509v3/v3_bitst.c index eb6d0f3654..9072b4228e 100644 --- a/crypto/x509v3/v3_bitst.c +++ b/crypto/x509v3/v3_bitst.c @@ -112,7 +112,7 @@ ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, ASN1_BIT_STRING *bs; int i; BIT_STRING_BITNAME *bnam; - if (!(bs = ASN1_BIT_STRING_new())) { + if ((bs = ASN1_BIT_STRING_new()) == NULL) { X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/x509v3/v3_conf.c b/crypto/x509v3/v3_conf.c index 672d3de977..51f39f5ed1 100644 --- a/crypto/x509v3/v3_conf.c +++ b/crypto/x509v3/v3_conf.c @@ -121,11 +121,12 @@ static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, X509_EXTENSION *ext; STACK_OF(CONF_VALUE) *nval; void *ext_struc; + if (ext_nid == NID_undef) { X509V3err(X509V3_F_DO_EXT_NCONF, X509V3_R_UNKNOWN_EXTENSION_NAME); return NULL; } - if (!(method = X509V3_EXT_get_nid(ext_nid))) { + if ((method = X509V3_EXT_get_nid(ext_nid)) == NULL) { X509V3err(X509V3_F_DO_EXT_NCONF, X509V3_R_UNKNOWN_EXTENSION); return NULL; } @@ -148,14 +149,14 @@ static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, if (!ext_struc) return NULL; } else if (method->s2i) { - if (!(ext_struc = method->s2i(method, ctx, value))) + if ((ext_struc = method->s2i(method, ctx, value)) == NULL) return NULL; } else if (method->r2i) { if (!ctx->db || !ctx->db_meth) { X509V3err(X509V3_F_DO_EXT_NCONF, X509V3_R_NO_CONFIG_DATABASE); return NULL; } - if (!(ext_struc = method->r2i(method, ctx, value))) + if ((ext_struc = method->r2i(method, ctx, value)) == NULL) return NULL; } else { X509V3err(X509V3_F_DO_EXT_NCONF, @@ -189,13 +190,14 @@ static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method, goto merr; } else { unsigned char *p; + ext_len = method->i2d(ext_struc, NULL); - if (!(ext_der = OPENSSL_malloc(ext_len))) + if ((ext_der = OPENSSL_malloc(ext_len)) == NULL) goto merr; p = ext_der; method->i2d(ext_struc, &p); } - if (!(ext_oct = ASN1_OCTET_STRING_new())) + if ((ext_oct = ASN1_OCTET_STRING_new()) == NULL) goto merr; ext_oct->data = ext_der; ext_der = NULL; @@ -221,7 +223,8 @@ static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method, X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc) { const X509V3_EXT_METHOD *method; - if (!(method = X509V3_EXT_get_nid(ext_nid))) { + + if ((method = X509V3_EXT_get_nid(ext_nid)) == NULL) { X509V3err(X509V3_F_X509V3_EXT_I2D, X509V3_R_UNKNOWN_EXTENSION); return NULL; } @@ -271,7 +274,8 @@ static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, ASN1_OBJECT *obj = NULL; ASN1_OCTET_STRING *oct = NULL; X509_EXTENSION *extension = NULL; - if (!(obj = OBJ_txt2obj(ext, 0))) { + + if ((obj = OBJ_txt2obj(ext, 0)) == NULL) { X509V3err(X509V3_F_V3_GENERIC_EXTENSION, X509V3_R_EXTENSION_NAME_ERROR); ERR_add_error_data(2, "name=", ext); @@ -290,7 +294,7 @@ static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, goto err; } - if (!(oct = ASN1_OCTET_STRING_new())) { + if ((oct = ASN1_OCTET_STRING_new()) == NULL) { X509V3err(X509V3_F_V3_GENERIC_EXTENSION, ERR_R_MALLOC_FAILURE); goto err; } @@ -346,11 +350,12 @@ int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section, STACK_OF(CONF_VALUE) *nval; CONF_VALUE *val; int i; - if (!(nval = NCONF_get_section(conf, section))) + + if ((nval = NCONF_get_section(conf, section)) == NULL) return 0; for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { val = sk_CONF_VALUE_value(nval, i); - if (!(ext = X509V3_EXT_nconf(conf, ctx, val->name, val->value))) + if ((ext = X509V3_EXT_nconf(conf, ctx, val->name, val->value)) == NULL) return 0; if (ctx->flags == X509V3_CTX_REPLACE) delete_ext(*sk, ext); diff --git a/crypto/x509v3/v3_cpols.c b/crypto/x509v3/v3_cpols.c index b7f80792c1..cac91b94e1 100644 --- a/crypto/x509v3/v3_cpols.c +++ b/crypto/x509v3/v3_cpols.c @@ -176,10 +176,10 @@ static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, } pol = policy_section(ctx, polsect, ia5org); X509V3_section_free(ctx, polsect); - if (!pol) + if (pol == NULL) goto err; } else { - if (!(pobj = OBJ_txt2obj(cnf->name, 0))) { + if ((pobj = OBJ_txt2obj(cnf->name, 0)) == NULL) { X509V3err(X509V3_F_R2I_CERTPOL, X509V3_R_INVALID_OBJECT_IDENTIFIER); X509V3_conf_err(cnf); @@ -209,13 +209,14 @@ static POLICYINFO *policy_section(X509V3_CTX *ctx, CONF_VALUE *cnf; POLICYINFO *pol; POLICYQUALINFO *qual; - if (!(pol = POLICYINFO_new())) + + if ((pol = POLICYINFO_new()) == NULL) goto merr; for (i = 0; i < sk_CONF_VALUE_num(polstrs); i++) { cnf = sk_CONF_VALUE_value(polstrs, i); if (strcmp(cnf->name, "policyIdentifier") == 0) { ASN1_OBJECT *pobj; - if (!(pobj = OBJ_txt2obj(cnf->value, 0))) { + if ((pobj = OBJ_txt2obj(cnf->value, 0)) == NULL) { X509V3err(X509V3_F_POLICY_SECTION, X509V3_R_INVALID_OBJECT_IDENTIFIER); X509V3_conf_err(cnf); @@ -224,17 +225,17 @@ static POLICYINFO *policy_section(X509V3_CTX *ctx, pol->policyid = pobj; } else if (!name_cmp(cnf->name, "CPS")) { - if (!pol->qualifiers) + if (pol->qualifiers == NULL) pol->qualifiers = sk_POLICYQUALINFO_new_null(); - if (!(qual = POLICYQUALINFO_new())) + if ((qual = POLICYQUALINFO_new()) == NULL) goto merr; if (!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) goto merr; - if (!(qual->pqualid = OBJ_nid2obj(NID_id_qt_cps))) { + if ((qual->pqualid = OBJ_nid2obj(NID_id_qt_cps)) == NULL) { X509V3err(X509V3_F_POLICY_SECTION, ERR_R_INTERNAL_ERROR); goto err; } - if (!(qual->d.cpsuri = ASN1_IA5STRING_new())) + if ((qual->d.cpsuri = ASN1_IA5STRING_new()) == NULL) goto merr; if (!ASN1_STRING_set(qual->d.cpsuri, cnf->value, strlen(cnf->value))) @@ -292,19 +293,20 @@ static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, CONF_VALUE *cnf; USERNOTICE *not; POLICYQUALINFO *qual; - if (!(qual = POLICYQUALINFO_new())) + + if ((qual = POLICYQUALINFO_new()) == NULL) goto merr; - if (!(qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice))) { + if ((qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice)) == NULL) { X509V3err(X509V3_F_NOTICE_SECTION, ERR_R_INTERNAL_ERROR); goto err; } - if (!(not = USERNOTICE_new())) + if ((not = USERNOTICE_new()) == NULL) goto merr; qual->d.usernotice = not; for (i = 0; i < sk_CONF_VALUE_num(unot); i++) { cnf = sk_CONF_VALUE_value(unot, i); if (strcmp(cnf->name, "explicitText") == 0) { - if (!(not->exptext = ASN1_VISIBLESTRING_new())) + if ((not->exptext = ASN1_VISIBLESTRING_new()) == NULL) goto merr; if (!ASN1_STRING_set(not->exptext, cnf->value, strlen(cnf->value))) @@ -312,7 +314,7 @@ static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, } else if (strcmp(cnf->name, "organization") == 0) { NOTICEREF *nref; if (!not->noticeref) { - if (!(nref = NOTICEREF_new())) + if ((nref = NOTICEREF_new()) == NULL) goto merr; not->noticeref = nref; } else @@ -328,7 +330,7 @@ static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, NOTICEREF *nref; STACK_OF(CONF_VALUE) *nos; if (!not->noticeref) { - if (!(nref = NOTICEREF_new())) + if ((nref = NOTICEREF_new()) == NULL) goto merr; not->noticeref = nref; } else @@ -376,7 +378,7 @@ static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos) for (i = 0; i < sk_CONF_VALUE_num(nos); i++) { cnf = sk_CONF_VALUE_value(nos, i); - if (!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) { + if ((aint = s2i_ASN1_INTEGER(NULL, cnf->name)) == NULL) { X509V3err(X509V3_F_NREF_NOS, X509V3_R_INVALID_NUMBER); goto err; } diff --git a/crypto/x509v3/v3_crld.c b/crypto/x509v3/v3_crld.c index b72ae43f87..67d019aeaa 100644 --- a/crypto/x509v3/v3_crld.c +++ b/crypto/x509v3/v3_crld.c @@ -291,7 +291,8 @@ static void *v2i_crld(const X509V3_EXT_METHOD *method, GENERAL_NAME *gen = NULL; CONF_VALUE *cnf; int i; - if (!(crld = sk_DIST_POINT_new_null())) + + if ((crld = sk_DIST_POINT_new_null()) == NULL) goto merr; for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { DIST_POINT *point; @@ -310,20 +311,20 @@ static void *v2i_crld(const X509V3_EXT_METHOD *method, goto merr; } } else { - if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) + if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL) goto err; - if (!(gens = GENERAL_NAMES_new())) + if ((gens = GENERAL_NAMES_new()) == NULL) goto merr; if (!sk_GENERAL_NAME_push(gens, gen)) goto merr; gen = NULL; - if (!(point = DIST_POINT_new())) + if ((point = DIST_POINT_new()) == NULL) goto merr; if (!sk_DIST_POINT_push(crld, point)) { DIST_POINT_free(point); goto merr; } - if (!(point->distpoint = DIST_POINT_NAME_new())) + if ((point->distpoint = DIST_POINT_NAME_new()) == NULL) goto merr; point->distpoint->name.fullname = gens; point->distpoint->type = 0; diff --git a/crypto/x509v3/v3_extku.c b/crypto/x509v3/v3_extku.c index 6092c2e4bd..70d3554519 100644 --- a/crypto/x509v3/v3_extku.c +++ b/crypto/x509v3/v3_extku.c @@ -125,7 +125,7 @@ static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, CONF_VALUE *val; int i; - if (!(extku = sk_ASN1_OBJECT_new_null())) { + if ((extku = sk_ASN1_OBJECT_new_null()) == NULL) { X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE, ERR_R_MALLOC_FAILURE); return NULL; } @@ -136,7 +136,7 @@ static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, extval = val->value; else extval = val->name; - if (!(objtmp = OBJ_txt2obj(extval, 0))) { + if ((objtmp = OBJ_txt2obj(extval, 0)) == NULL) { sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free); X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE, X509V3_R_INVALID_OBJECT_IDENTIFIER); diff --git a/crypto/x509v3/v3_ia5.c b/crypto/x509v3/v3_ia5.c index 42a0d86fb3..7cae1b6786 100644 --- a/crypto/x509v3/v3_ia5.c +++ b/crypto/x509v3/v3_ia5.c @@ -77,9 +77,10 @@ const X509V3_EXT_METHOD v3_ns_ia5_list[] = { char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5) { char *tmp; + if (!ia5 || !ia5->length) return NULL; - if (!(tmp = OPENSSL_malloc(ia5->length + 1))) { + if ((tmp = OPENSSL_malloc(ia5->length + 1)) == NULL) { X509V3err(X509V3_F_I2S_ASN1_IA5STRING, ERR_R_MALLOC_FAILURE); return NULL; } @@ -97,7 +98,7 @@ ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_R_INVALID_NULL_ARGUMENT); return NULL; } - if (!(ia5 = ASN1_IA5STRING_new())) + if ((ia5 = ASN1_IA5STRING_new()) == NULL) goto err; if (!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char *)str, strlen(str))) { diff --git a/crypto/x509v3/v3_info.c b/crypto/x509v3/v3_info.c index a377c92b76..872d5c7d9a 100644 --- a/crypto/x509v3/v3_info.c +++ b/crypto/x509v3/v3_info.c @@ -153,13 +153,14 @@ static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD ACCESS_DESCRIPTION *acc; int i, objlen; char *objtmp, *ptmp; - if (!(ainfo = sk_ACCESS_DESCRIPTION_new_null())) { + + if ((ainfo = sk_ACCESS_DESCRIPTION_new_null()) == NULL) { X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, ERR_R_MALLOC_FAILURE); return NULL; } for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { cnf = sk_CONF_VALUE_value(nval, i); - if (!(acc = ACCESS_DESCRIPTION_new()) + if ((acc = ACCESS_DESCRIPTION_new()) == NULL || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) { X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, ERR_R_MALLOC_FAILURE); @@ -176,7 +177,7 @@ static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD ctmp.value = cnf->value; if (!v2i_GENERAL_NAME_ex(acc->location, method, ctx, &ctmp, 0)) goto err; - if (!(objtmp = OPENSSL_malloc(objlen + 1))) { + if ((objtmp = OPENSSL_malloc(objlen + 1)) == NULL) { X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, ERR_R_MALLOC_FAILURE); goto err; diff --git a/crypto/x509v3/v3_lib.c b/crypto/x509v3/v3_lib.c index c091b043de..4bec817c7a 100644 --- a/crypto/x509v3/v3_lib.c +++ b/crypto/x509v3/v3_lib.c @@ -73,7 +73,8 @@ static void ext_list_free(X509V3_EXT_METHOD *ext); int X509V3_EXT_add(X509V3_EXT_METHOD *ext) { - if (!ext_list && !(ext_list = sk_X509V3_EXT_METHOD_new(ext_cmp))) { + if (ext_list == NULL + && (ext_list = sk_X509V3_EXT_METHOD_new(ext_cmp)) == NULL) { X509V3err(X509V3_F_X509V3_EXT_ADD, ERR_R_MALLOC_FAILURE); return 0; } @@ -135,12 +136,11 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from) const X509V3_EXT_METHOD *ext; X509V3_EXT_METHOD *tmpext; - if (!(ext = X509V3_EXT_get_nid(nid_from))) { - X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS, - X509V3_R_EXTENSION_NOT_FOUND); + if ((ext = X509V3_EXT_get_nid(nid_from)) == NULL) { + X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS, X509V3_R_EXTENSION_NOT_FOUND); return 0; } - if (!(tmpext = OPENSSL_malloc(sizeof(*tmpext)))) { + if ((tmpext = OPENSSL_malloc(sizeof(*tmpext))) == NULL) { X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS, ERR_R_MALLOC_FAILURE); return 0; } @@ -181,7 +181,7 @@ void *X509V3_EXT_d2i(X509_EXTENSION *ext) ASN1_STRING *extvalue; int extlen; - if (!(method = X509V3_EXT_get(ext))) + if ((method = X509V3_EXT_get(ext)) == NULL) return NULL; extvalue = X509_EXTENSION_get_data(ext); p = ASN1_STRING_data(extvalue); @@ -326,7 +326,8 @@ int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, return 1; } - if (!*x && !(*x = sk_X509_EXTENSION_new_null())) + if (*x == NULL + && (*x = sk_X509_EXTENSION_new_null()) == NULL) return -1; if (!sk_X509_EXTENSION_push(*x, ext)) return -1; diff --git a/crypto/x509v3/v3_pci.c b/crypto/x509v3/v3_pci.c index 2568ea8bc9..c795db787d 100644 --- a/crypto/x509v3/v3_pci.c +++ b/crypto/x509v3/v3_pci.c @@ -86,7 +86,7 @@ static int process_pci_value(CONF_VALUE *val, X509V3_conf_err(val); return 0; } - if (!(*language = OBJ_txt2obj(val->value, 0))) { + if ((*language = OBJ_txt2obj(val->value, 0)) == NULL) { X509V3err(X509V3_F_PROCESS_PCI_VALUE, X509V3_R_INVALID_OBJECT_IDENTIFIER); X509V3_conf_err(val); diff --git a/crypto/x509v3/v3_pcons.c b/crypto/x509v3/v3_pcons.c index 3349cef027..a1b27d6ae3 100644 --- a/crypto/x509v3/v3_pcons.c +++ b/crypto/x509v3/v3_pcons.c @@ -108,7 +108,8 @@ static void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, POLICY_CONSTRAINTS *pcons = NULL; CONF_VALUE *val; int i; - if (!(pcons = POLICY_CONSTRAINTS_new())) { + + if ((pcons = POLICY_CONSTRAINTS_new()) == NULL) { X509V3err(X509V3_F_V2I_POLICY_CONSTRAINTS, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/x509v3/v3_pmaps.c b/crypto/x509v3/v3_pmaps.c index a168343b82..14253aae35 100644 --- a/crypto/x509v3/v3_pmaps.c +++ b/crypto/x509v3/v3_pmaps.c @@ -119,7 +119,7 @@ static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, CONF_VALUE *val; int i; - if (!(pmaps = sk_POLICY_MAPPING_new_null())) { + if ((pmaps = sk_POLICY_MAPPING_new_null()) == NULL) { X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/x509v3/v3_prn.c b/crypto/x509v3/v3_prn.c index 633dacafc2..2d51674972 100644 --- a/crypto/x509v3/v3_prn.c +++ b/crypto/x509v3/v3_prn.c @@ -131,7 +131,7 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, p = ASN1_STRING_data(extoct); extlen = ASN1_STRING_length(extoct); - if (!(method = X509V3_EXT_get(ext))) + if ((method = X509V3_EXT_get(ext)) == NULL) return unknown_ext_print(out, p, extlen, flag, indent, 0); if (method->it) ext_str = ASN1_item_d2i(NULL, &p, extlen, ASN1_ITEM_ptr(method->it)); @@ -142,7 +142,7 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, return unknown_ext_print(out, p, extlen, flag, indent, 1); if (method->i2s) { - if (!(value = method->i2s(method, ext_str))) { + if ((value = method->i2s(method, ext_str)) == NULL) { ok = 0; goto err; } @@ -162,7 +162,7 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, } #endif } else if (method->i2v) { - if (!(nval = method->i2v(method, ext_str, NULL))) { + if ((nval = method->i2v(method, ext_str, NULL)) == NULL) { ok = 0; goto err; } @@ -249,7 +249,8 @@ int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent) { BIO *bio_tmp; int ret; - if (!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) + + if ((bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) return 0; ret = X509V3_EXT_print(bio_tmp, ext, flag, indent); BIO_free(bio_tmp); diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c index beb8b2f870..dc72795978 100644 --- a/crypto/x509v3/v3_purp.c +++ b/crypto/x509v3/v3_purp.c @@ -209,7 +209,7 @@ int X509_PURPOSE_add(int id, int trust, int flags, idx = X509_PURPOSE_get_by_id(id); /* Need a new entry */ if (idx == -1) { - if (!(ptmp = OPENSSL_malloc(sizeof(*ptmp)))) { + if ((ptmp = OPENSSL_malloc(sizeof(*ptmp))) == NULL) { X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE); return 0; } @@ -241,7 +241,8 @@ int X509_PURPOSE_add(int id, int trust, int flags, /* If its a new entry manage the dynamic table */ if (idx == -1) { - if (!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) { + if (xptable == NULL + && (xptable = sk_X509_PURPOSE_new(xp_cmp)) == NULL) { X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/x509v3/v3_skey.c b/crypto/x509v3/v3_skey.c index 705d86cb52..977844b55a 100644 --- a/crypto/x509v3/v3_skey.c +++ b/crypto/x509v3/v3_skey.c @@ -83,12 +83,12 @@ ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct; long length; - if (!(oct = ASN1_OCTET_STRING_new())) { + if ((oct = ASN1_OCTET_STRING_new()) == NULL) { X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE); return NULL; } - if (!(oct->data = string_to_hex(str, &length))) { + if ((oct->data = string_to_hex(str, &length)) == NULL) { ASN1_OCTET_STRING_free(oct); return NULL; } @@ -110,7 +110,7 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, if (strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str); - if (!(oct = ASN1_OCTET_STRING_new())) { + if ((oct = ASN1_OCTET_STRING_new()) == NULL) { X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/x509v3/v3_sxnet.c b/crypto/x509v3/v3_sxnet.c index ecd1ec6ffb..fff3b00774 100644 --- a/crypto/x509v3/v3_sxnet.c +++ b/crypto/x509v3/v3_sxnet.c @@ -152,8 +152,9 @@ static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen) { - ASN1_INTEGER *izone = NULL; - if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) { + ASN1_INTEGER *izone; + + if ((izone = s2i_ASN1_INTEGER(NULL, zone)) == NULL) { X509V3err(X509V3_F_SXNET_ADD_ID_ASC, X509V3_R_ERROR_CONVERTING_ZONE); return 0; } @@ -165,8 +166,10 @@ int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen) int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen) { - ASN1_INTEGER *izone = NULL; - if (!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { + ASN1_INTEGER *izone; + + if ((izone = ASN1_INTEGER_new()) == NULL + || !ASN1_INTEGER_set(izone, lzone)) { X509V3err(X509V3_F_SXNET_ADD_ID_ULONG, ERR_R_MALLOC_FAILURE); ASN1_INTEGER_free(izone); return 0; @@ -196,8 +199,8 @@ int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, X509V3_R_USER_TOO_LONG); return 0; } - if (!*psx) { - if (!(sx = SXNET_new())) + if (*psx == NULL) { + if ((sx = SXNET_new()) == NULL) goto err; if (!ASN1_INTEGER_set(sx->version, 0)) goto err; @@ -209,7 +212,7 @@ int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, return 0; } - if (!(id = SXNETID_new())) + if ((id = SXNETID_new()) == NULL) goto err; if (userlen == -1) userlen = strlen(user); @@ -231,9 +234,10 @@ int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone) { - ASN1_INTEGER *izone = NULL; + ASN1_INTEGER *izone; ASN1_OCTET_STRING *oct; - if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) { + + if ((izone = s2i_ASN1_INTEGER(NULL, zone)) == NULL) { X509V3err(X509V3_F_SXNET_GET_ID_ASC, X509V3_R_ERROR_CONVERTING_ZONE); return NULL; } @@ -244,9 +248,11 @@ ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone) ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone) { - ASN1_INTEGER *izone = NULL; + ASN1_INTEGER *izone; ASN1_OCTET_STRING *oct; - if (!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { + + if ((izone = ASN1_INTEGER_new()) == NULL + || !ASN1_INTEGER_set(izone, lzone)) { X509V3err(X509V3_F_SXNET_GET_ID_ULONG, ERR_R_MALLOC_FAILURE); ASN1_INTEGER_free(izone); return NULL; diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c index c6aab4b95d..d50c2fa26c 100644 --- a/crypto/x509v3/v3_utl.c +++ b/crypto/x509v3/v3_utl.c @@ -84,13 +84,14 @@ int X509V3_add_value(const char *name, const char *value, { CONF_VALUE *vtmp = NULL; char *tname = NULL, *tvalue = NULL; - if (name && !(tname = BUF_strdup(name))) + + if (name && (tname = BUF_strdup(name)) == NULL) goto err; - if (value && !(tvalue = BUF_strdup(value))) + if (value && (tvalue = BUF_strdup(value)) == NULL) goto err; - if (!(vtmp = OPENSSL_malloc(sizeof(*vtmp)))) + if ((vtmp = OPENSSL_malloc(sizeof(*vtmp))) == NULL) goto err; - if (!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) + if (*extlist == NULL && (*extlist = sk_CONF_VALUE_new_null()) == NULL) goto err; vtmp->section = NULL; vtmp->name = tname; @@ -144,10 +145,11 @@ char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *a) { BIGNUM *bntmp = NULL; char *strtmp = NULL; + if (!a) return NULL; - if (!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) || - !(strtmp = BN_bn2dec(bntmp))) + if ((bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) == NULL + || (strtmp = BN_bn2dec(bntmp)) == NULL) X509V3err(X509V3_F_I2S_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE); BN_free(bntmp); return strtmp; @@ -157,10 +159,11 @@ char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a) { BIGNUM *bntmp = NULL; char *strtmp = NULL; + if (!a) return NULL; - if (!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) || - !(strtmp = BN_bn2dec(bntmp))) + if ((bntmp = ASN1_INTEGER_to_BN(a, NULL)) == NULL + || (strtmp = BN_bn2dec(bntmp)) == NULL) X509V3err(X509V3_F_I2S_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); BN_free(bntmp); return strtmp; @@ -220,9 +223,10 @@ int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint, { char *strtmp; int ret; + if (!aint) return 1; - if (!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) + if ((strtmp = i2s_ASN1_INTEGER(NULL, aint)) == NULL) return 0; ret = X509V3_add_value(name, strtmp, extlist); OPENSSL_free(strtmp); @@ -232,7 +236,8 @@ int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint, int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool) { char *btmp; - if (!(btmp = value->value)) + + if ((btmp = value->value) == NULL) goto err; if (strcmp(btmp, "TRUE") == 0 || strcmp(btmp, "true") == 0 @@ -262,7 +267,8 @@ int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool) int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint) { ASN1_INTEGER *itmp; - if (!(itmp = s2i_ASN1_INTEGER(NULL, value->value))) { + + if ((itmp = s2i_ASN1_INTEGER(NULL, value->value)) == NULL) { X509V3_conf_err(value); return 0; } @@ -401,7 +407,7 @@ char *hex_to_string(const unsigned char *buffer, long len) const static char hexdig[] = "0123456789ABCDEF"; if (!buffer || !len) return NULL; - if (!(tmp = OPENSSL_malloc(len * 3 + 1))) { + if ((tmp = OPENSSL_malloc(len * 3 + 1)) == NULL) { X509V3err(X509V3_F_HEX_TO_STRING, ERR_R_MALLOC_FAILURE); return NULL; } @@ -431,7 +437,7 @@ unsigned char *string_to_hex(const char *str, long *len) X509V3err(X509V3_F_STRING_TO_HEX, X509V3_R_INVALID_NULL_ARGUMENT); return NULL; } - if (!(hexbuf = OPENSSL_malloc(strlen(str) >> 1))) + if ((hexbuf = OPENSSL_malloc(strlen(str) >> 1)) == NULL) goto err; for (p = (unsigned char *)str, q = hexbuf; *p;) { ch = *p++; diff --git a/crypto/x509v3/v3prin.c b/crypto/x509v3/v3prin.c index cbc357079d..36ca040bc5 100644 --- a/crypto/x509v3/v3prin.c +++ b/crypto/x509v3/v3prin.c @@ -69,17 +69,18 @@ int main(int argc, char **argv) FILE *inf; int i, count; X509_EXTENSION *ext; + X509V3_add_standard_extensions(); ERR_load_crypto_strings(); if (!argv[1]) { fprintf(stderr, "Usage v3prin cert.pem\n"); exit(1); } - if (!(inf = fopen(argv[1], "r"))) { + if ((inf = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Can't open %s\n", argv[1]); exit(1); } - if (!(cert = PEM_read_X509(inf, NULL, NULL))) { + if ((cert = PEM_read_X509(inf, NULL, NULL)) == NULL) { fprintf(stderr, "Can't read certificate %s\n", argv[1]); ERR_print_errors_fp(stderr); exit(1); diff --git a/demos/engines/cluster_labs/hw_cluster_labs.c b/demos/engines/cluster_labs/hw_cluster_labs.c index 918689c215..e1f251c336 100644 --- a/demos/engines/cluster_labs/hw_cluster_labs.c +++ b/demos/engines/cluster_labs/hw_cluster_labs.c @@ -319,23 +319,18 @@ int cluster_labs_init(ENGINE *e) goto err; } /* bind functions */ - if (! - (p1 = - (cl_engine_init *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F1)) -|| !(p2 = (cl_mod_exp *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F2)) -|| !(p3 = (cl_mod_exp_crt *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F3)) -|| !(p4 = (cl_rsa_mod_exp *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F4)) -|| !(p5 = - (cl_rsa_priv_enc *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F5)) -|| !(p6 = - (cl_rsa_priv_dec *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F6)) -|| !(p7 = (cl_rsa_pub_enc *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F7)) -|| !(p8 = (cl_rsa_pub_dec *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F8)) -|| !(p20 = - (cl_rand_bytes *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F20)) -|| !(p30 = (cl_dsa_sign *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F30)) -|| !(p31 = - (cl_dsa_verify *) DSO_bind_func(cluster_labs_dso, CLUSTER_LABS_F31))) { +#define BINDIT(t, name) (t *)DSO_bind_func(cluster_labs_dso, name) + if ((p1 = (cl_engine_init, CLUSTER_LABS_F1)) == NULL + || (p2 = BINDIT(cl_mod_exp, CLUSTER_LABS_F2)) == NULL + || (p3 = BINDIT(cl_mod_exp_crt, CLUSTER_LABS_F3)) == NULL + || (p4 = BINDIT(cl_rsa_mod_exp, CLUSTER_LABS_F4)) == NULL + || (p5 = BINDIT(cl_rsa_priv_enc, CLUSTER_LABS_F5)) == NULL + || (p6 = BINDIT(cl_rsa_priv_dec, CLUSTER_LABS_F6)) == NULL + || (p7 = BINDIT(cl_rsa_pub_enc, CLUSTER_LABS_F7)) == NULL + || (p8 = BINDIT(cl_rsa_pub_dec, CLUSTER_LABS_F8)) == NULL + || (p20 = BINDIT(cl_rand_bytes, CLUSTER_LABS_F20)) == NULL + || (p30 = BINDIT(cl_dsa_sign, CLUSTER_LABS_F30)) == NULL + || (p31 = BINDIT(cl_dsa_verify, CLUSTER_LABS_F31)) == NULL) { CLerr(CL_F_CLUSTER_LABS_INIT, CL_R_DSO_FAILURE); goto err; } diff --git a/demos/engines/ibmca/hw_ibmca.c b/demos/engines/ibmca/hw_ibmca.c index 5017d6490d..29f8547698 100644 --- a/demos/engines/ibmca/hw_ibmca.c +++ b/demos/engines/ibmca/hw_ibmca.c @@ -388,11 +388,11 @@ static int ibmca_init(ENGINE *e) goto err; } - if (!(p1 = DSO_bind_func(ibmca_dso, IBMCA_F1)) || - !(p2 = DSO_bind_func(ibmca_dso, IBMCA_F2)) || - !(p3 = DSO_bind_func(ibmca_dso, IBMCA_F3)) || - !(p4 = DSO_bind_func(ibmca_dso, IBMCA_F4)) || - !(p5 = DSO_bind_func(ibmca_dso, IBMCA_F5))) { + if ((p1 = DSO_bind_func(ibmca_dso, IBMCA_F1)) == NULL + || (p2 = DSO_bind_func(ibmca_dso, IBMCA_F2)) == NULL + || (p3 = DSO_bind_func(ibmca_dso, IBMCA_F3)) == NULL + || (p4 = DSO_bind_func(ibmca_dso, IBMCA_F4)) == NULL + || (p5 = DSO_bind_func(ibmca_dso, IBMCA_F5)) == NULL) { IBMCAerr(IBMCA_F_IBMCA_INIT, IBMCA_R_DSO_FAILURE); goto err; } diff --git a/demos/engines/zencod/hw_zencod.c b/demos/engines/zencod/hw_zencod.c index 773674f444..f13cf37522 100644 --- a/demos/engines/zencod/hw_zencod.c +++ b/demos/engines/zencod/hw_zencod.c @@ -538,46 +538,28 @@ static int zencod_init(ENGINE *e) /* * Trying to load Function from the Library */ - if (! - (ptr_1 = - (t_zencod_bytes2bits *) DSO_bind_func(zencod_dso, ZENCOD_Fct_1)) -|| !(ptr_2 = (t_zencod_bits2bytes *) DSO_bind_func(zencod_dso, ZENCOD_Fct_2)) -|| !(ptr_3 = (t_zencod_new_number *) DSO_bind_func(zencod_dso, ZENCOD_Fct_3)) -|| !(ptr_4 = (t_zencod_init_number *) DSO_bind_func(zencod_dso, ZENCOD_Fct_4)) -|| !(ptr_exp_1 = - (t_zencod_rsa_mod_exp *) DSO_bind_func(zencod_dso, ZENCOD_Fct_exp_1)) -|| !(ptr_exp_2 = - (t_zencod_rsa_mod_exp_crt *) DSO_bind_func(zencod_dso, ZENCOD_Fct_exp_2)) -|| !(ptr_dsa_1 = - (t_zencod_dsa_do_sign *) DSO_bind_func(zencod_dso, ZENCOD_Fct_dsa_1)) -|| !(ptr_dsa_2 = - (t_zencod_dsa_do_verify *) DSO_bind_func(zencod_dso, ZENCOD_Fct_dsa_2)) -|| !(ptr_dh_1 = - (t_zencod_dh_generate_key *) DSO_bind_func(zencod_dso, ZENCOD_Fct_dh_1)) -|| !(ptr_dh_2 = - (t_zencod_dh_compute_key *) DSO_bind_func(zencod_dso, ZENCOD_Fct_dh_2)) -|| !(ptr_rand_1 = - (t_zencod_rand_bytes *) DSO_bind_func(zencod_dso, ZENCOD_Fct_rand_1)) -|| !(ptr_math_1 = - (t_zencod_math_mod_exp *) DSO_bind_func(zencod_dso, ZENCOD_Fct_math_1)) -|| !(ptr_0 = (t_zencod_test *) DSO_bind_func(zencod_dso, ZENCOD_Fct_0)) -|| !(ptr_md5_1 = - (t_zencod_md5_init *) DSO_bind_func(zencod_dso, ZENCOD_Fct_md5_1)) -|| !(ptr_md5_2 = - (t_zencod_md5_update *) DSO_bind_func(zencod_dso, ZENCOD_Fct_md5_2)) -|| !(ptr_md5_3 = - (t_zencod_md5_do_final *) DSO_bind_func(zencod_dso, ZENCOD_Fct_md5_3)) -|| !(ptr_sha1_1 = - (t_zencod_sha1_init *) DSO_bind_func(zencod_dso, ZENCOD_Fct_sha1_1)) -|| !(ptr_sha1_2 = - (t_zencod_sha1_update *) DSO_bind_func(zencod_dso, ZENCOD_Fct_sha1_2)) -|| !(ptr_sha1_3 = - (t_zencod_sha1_do_final *) DSO_bind_func(zencod_dso, ZENCOD_Fct_sha1_3)) -|| !(ptr_xdes_1 = - (t_zencod_xdes_cipher *) DSO_bind_func(zencod_dso, ZENCOD_Fct_xdes_1)) -|| !(ptr_rc4_1 = - (t_zencod_rc4_cipher *) DSO_bind_func(zencod_dso, ZENCOD_Fct_rc4_1))) { - +#define BINDIT(t, name) (t*)DSO_bindfunc(zencod_dso, name) + if ((ptr_1 = BINDIT(t_zencod_bytes2bits ZENCOD_Fct_1)) == NULL + || (ptr_2 = BINDIT(t_zencod_bits2bytes ZENCOD_Fct_2)) == NULL + || (ptr_3 = BINDIT(t_zencod_new_number ZENCOD_Fct_3)) == NULL + || (ptr_4 = BINDIT(t_zencod_init_number ZENCOD_Fct_4)) == NULL + || (ptr_exp_1 = BINDIT(t_zencod_rsa_mod_exp, ZENCOD_Fct_exp_1)) == NULL + || (ptr_exp_2 = BINDIT(t_zencod_rsa_mod_exp_crt, ZENCOD_Fct_exp_2)) == NULL + || (ptr_dsa_1 = BINDIT(t_zencod_dsa_do_sign, ZENCOD_Fct_dsa_1)) == NULL + || (ptr_dsa_2 = BINDIT(t_zencod_dsa_do_verify, ZENCOD_Fct_dsa_2)) == NULL + || (ptr_dh_1 = BINDIT(t_zencod_dh_generate_key, ZENCOD_Fct_dh_1)) == NULL + || (ptr_dh_2 = BINDIT(t_zencod_dh_compute_key, ZENCOD_Fct_dh_2)) == NULL + || (ptr_rand_1 = BINDIT(t_zencod_rand_bytes, ZENCOD_Fct_rand_1)) == NULL + || (ptr_math_1 = BINDIT(t_zencod_math_mod_exp, ZENCOD_Fct_math_1)) == NULL + || (ptr_0 = BINDIT(t_zencod_test, ZENCOD_Fct_0)) == NULL + || (ptr_md5_1 = BINDIT(t_zencod_md5_init, ZENCOD_Fct_md5_1)) == NULL + || (ptr_md5_2 = BINDIT(t_zencod_md5_update, ZENCOD_Fct_md5_2)) == NULL + || (ptr_md5_3 = BINDIT(t_zencod_md5_do_final, ZENCOD_Fct_md5_3)) == NULL + || (ptr_sha1_1 = BINDIT(t_zencod_sha1_init, ZENCOD_Fct_sha1_1)) == NULL + || (ptr_sha1_2 = BINDIT(t_zencod_sha1_update, ZENCOD_Fct_sha1_2)) == NULL + || (ptr_sha1_3 = BINDIT(t_zencod_sha1_do_final, ZENCOD_Fct_sha1_3)) == NULL + || (ptr_xdes_1 = BINDIT(t_zencod_xdes_cipher, ZENCOD_Fct_xdes_1)) == NULL + || (ptr_rc4_1 = BINDIT(t_zencod_rc4_cipher, ZENCOD_Fct_rc4_1)) == NULL) { ZENCODerr(ZENCOD_F_ZENCOD_INIT, ZENCOD_R_DSO_FAILURE); goto err; } @@ -906,7 +888,7 @@ static DSA_SIG *DSA_zencod_do_sign(const unsigned char *dgst, int dlen, return meth->dsa_do_sign(dgst, dlen, dsa); } - if (!(bn_s = BN_new()) || !(bn_r = BN_new())) { + if ((bn_s = BN_new()) == NULL || (bn_r = BN_new()) == NULL) { ENGINEerr(ZENCOD_F_ZENCOD_DSA_DO_SIGN, ZENCOD_R_BAD_KEY_COMPONENTS); goto FAILED; } @@ -935,7 +917,7 @@ static DSA_SIG *DSA_zencod_do_sign(const unsigned char *dgst, int dlen, goto FAILED; } - if (!(sig = DSA_SIG_new())) { + if ((sig = DSA_SIG_new()) == NULL) { ENGINEerr(ZENCOD_F_ZENCOD_DSA_DO_SIGN, ZENCOD_R_REQUEST_FAILED); goto FAILED; } @@ -1032,7 +1014,7 @@ static int DH_zencod_generate_key(DH *dh) bn_prv = dh->priv_key; generate_x = 0; } else { - if (!(bn_prv = BN_new())) { + if ((bn_prv = BN_new()) == NULL) { ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_BN_EXPAND_FAIL); goto FAILED; } @@ -1042,7 +1024,7 @@ static int DH_zencod_generate_key(DH *dh) /* Public key */ if (dh->pub_key) bn_pub = dh->pub_key; - else if (!(bn_pub = BN_new())) { + else if ((bn_pub = BN_new()) == NULL) { ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_BN_EXPAND_FAIL); goto FAILED; } diff --git a/demos/pkcs12/pkread.c b/demos/pkcs12/pkread.c index f4a3df4079..1086dbc463 100644 --- a/demos/pkcs12/pkread.c +++ b/demos/pkcs12/pkread.c @@ -22,7 +22,7 @@ int main(int argc, char **argv) } OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); - if (!(fp = fopen(argv[1], "rb"))) { + if ((fp = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "Error opening file %s\n", argv[1]); exit(1); } @@ -39,7 +39,7 @@ int main(int argc, char **argv) exit(1); } PKCS12_free(p12); - if (!(fp = fopen(argv[3], "w"))) { + if ((fp = fopen(argv[3], "w")) == NULL) { fprintf(stderr, "Error opening file %s\n", argv[1]); exit(1); } diff --git a/demos/pkcs12/pkwrite.c b/demos/pkcs12/pkwrite.c index fed773ea76..34e82dd6b9 100644 --- a/demos/pkcs12/pkwrite.c +++ b/demos/pkcs12/pkwrite.c @@ -20,7 +20,7 @@ int main(int argc, char **argv) } SSLeay_add_all_algorithms(); ERR_load_crypto_strings(); - if (!(fp = fopen(argv[1], "r"))) { + if ((fp = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Error opening file %s\n", argv[1]); exit(1); } @@ -34,7 +34,7 @@ int main(int argc, char **argv) ERR_print_errors_fp(stderr); exit(1); } - if (!(fp = fopen(argv[4], "wb"))) { + if ((fp = fopen(argv[4], "wb")) == NULL) { fprintf(stderr, "Error opening file %s\n", argv[1]); ERR_print_errors_fp(stderr); exit(1); diff --git a/engines/ccgost/gost2001.c b/engines/ccgost/gost2001.c index 8b56a30471..6d41f31f21 100644 --- a/engines/ccgost/gost2001.c +++ b/engines/ccgost/gost2001.c @@ -393,7 +393,7 @@ int gost2001_compute_public(EC_KEY *ec) goto err; } BN_CTX_start(ctx); - if (!(priv_key = EC_KEY_get0_private_key(ec))) { + if ((priv_key = EC_KEY_get0_private_key(ec)) == NULL) { GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, ERR_R_EC_LIB); goto err; } diff --git a/engines/ccgost/gost_ameth.c b/engines/ccgost/gost_ameth.c index b6c47f086b..5ca3a6e629 100644 --- a/engines/ccgost/gost_ameth.c +++ b/engines/ccgost/gost_ameth.c @@ -200,7 +200,7 @@ BIGNUM *gost_get0_priv_key(const EVP_PKEY *pkey) if (!ec) { return NULL; } - if (!(priv = EC_KEY_get0_private_key(ec))) + if ((priv = EC_KEY_get0_private_key(ec)) == NULL) return NULL; return (BIGNUM *)priv; } diff --git a/engines/e_4758cca.c b/engines/e_4758cca.c index e592cfb611..396f2c2b6a 100644 --- a/engines/e_4758cca.c +++ b/engines/e_4758cca.c @@ -290,28 +290,21 @@ static int ibm_4758_cca_init(ENGINE *e) CCA4758err(CCA4758_F_IBM_4758_CCA_INIT, CCA4758_R_DSO_FAILURE); goto err; } +#define BINDIT(t, name) (t)DSO_bind_func(dso, name) # ifndef OPENSSL_NO_RSA - if (!(keyRecordRead = (F_KEYRECORDREAD) - DSO_bind_func(dso, n_keyRecordRead)) || - !(randomNumberGenerate = (F_RANDOMNUMBERGENERATE) - DSO_bind_func(dso, n_randomNumberGenerate)) || - !(digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE) - DSO_bind_func(dso, n_digitalSignatureGenerate)) || - !(digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY) - DSO_bind_func(dso, n_digitalSignatureVerify)) || - !(publicKeyExtract = (F_PUBLICKEYEXTRACT) - DSO_bind_func(dso, n_publicKeyExtract)) || - !(pkaEncrypt = (F_PKAENCRYPT) - DSO_bind_func(dso, n_pkaEncrypt)) || !(pkaDecrypt = (F_PKADECRYPT) - DSO_bind_func(dso, - n_pkaDecrypt))) + if ((keyRecordRead = BINDIT(F_KEYRECORDREAD, n_keyRecordRead)) == NULL + || (randomNumberGenerate = BINDIT(F_RANDOMNUMBERGENERATE, n_randomNumberGenerate)) == NULL + || (digitalSignatureGenerate = BINDIT(F_DIGITALSIGNATUREGENERATE, n_digitalSignatureGenerate)) == NULL + || (digitalSignatureVerify = BINDIT(F_DIGITALSIGNATUREVERIFY, n_digitalSignatureVerify)) == NULL + || (publicKeyExtract = BINDIT(F_PUBLICKEYEXTRACT, n_publicKeyExtract)) == NULL + || (pkaEncrypt = BINDIT(F_PKAENCRYPT, n_pkaEncrypt)) == NULL + || (pkaDecrypt = BINDIT(F_PKADECRYPT, n_pkaDecrypt)) == NULL) { CCA4758err(CCA4758_F_IBM_4758_CCA_INIT, CCA4758_R_DSO_FAILURE); goto err; } # else - if (!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE) - DSO_bind_func(dso, n_randomNumberGenerate))) { + if ((randomNumberGenerate = BINDIT(F_RANDOMNUMBERGENERATE, n_randomNumberGenerate)) == NULL) { CCA4758err(CCA4758_F_IBM_4758_CCA_INIT, CCA4758_R_DSO_FAILURE); goto err; } diff --git a/engines/e_aep.c b/engines/e_aep.c index 8a47f7d057..abcdb1538f 100644 --- a/engines/e_aep.c +++ b/engines/e_aep.c @@ -462,22 +462,22 @@ static int aep_init(ENGINE *e) /* Attempt to load libaep.so. */ aep_dso = DSO_load(NULL, get_AEP_LIBNAME(), NULL, 0); - if (aep_dso == NULL) { AEPHKerr(AEPHK_F_AEP_INIT, AEPHK_R_NOT_LOADED); goto err; } - if (!(p1 = (t_AEP_ModExp *) DSO_bind_func(aep_dso, AEP_F1)) || - !(p2 = (t_AEP_ModExpCrt *) DSO_bind_func(aep_dso, AEP_F2)) || +#define BINDIT(t, name) (t *)DSO_bind_func(aep_dso, name) + if ((p1 = BINDIT(t_AEP_ModExp, AEP_F1)) == NULL + || (p2 = BINDIT(t_AEP_ModExpCrt, AEP_F2)) == NULL # ifdef AEPRAND - !(p3 = (t_AEP_GenRandom *) DSO_bind_func(aep_dso, AEP_F3)) || + || (p3 = BINDIT(t_AEP_GenRandom, AEP_F3)) == NULL # endif - !(p4 = (t_AEP_Finalize *) DSO_bind_func(aep_dso, AEP_F4)) || - !(p5 = (t_AEP_Initialize *) DSO_bind_func(aep_dso, AEP_F5)) || - !(p6 = (t_AEP_OpenConnection *) DSO_bind_func(aep_dso, AEP_F6)) || - !(p7 = (t_AEP_SetBNCallBacks *) DSO_bind_func(aep_dso, AEP_F7)) || - !(p8 = (t_AEP_CloseConnection *) DSO_bind_func(aep_dso, AEP_F8))) { + || (p4 = BINDIT(t_AEP_Finalize, AEP_F4)) == NULL + || (p5 = BINDIT(t_AEP_Initialize, AEP_F5)) == NULL + || (p6 = BINDIT(t_AEP_OpenConnection, AEP_F6)) == NULL + || (p7 = BINDIT(t_AEP_SetBNCallBacks, AEP_F7)) == NULL + || (p8 = BINDIT(t_AEP_CloseConnection, AEP_F8)) == NULL) { AEPHKerr(AEPHK_F_AEP_INIT, AEPHK_R_NOT_LOADED); goto err; } diff --git a/engines/e_atalla.c b/engines/e_atalla.c index 4bde213462..211f29f541 100644 --- a/engines/e_atalla.c +++ b/engines/e_atalla.c @@ -382,13 +382,10 @@ static int atalla_init(ENGINE *e) ATALLAerr(ATALLA_F_ATALLA_INIT, ATALLA_R_NOT_LOADED); goto err; } - if (! - (p1 = - (tfnASI_GetHardwareConfig *) DSO_bind_func(atalla_dso, ATALLA_F1)) -|| !(p2 = (tfnASI_RSAPrivateKeyOpFn *) DSO_bind_func(atalla_dso, ATALLA_F2)) -|| !(p3 = - (tfnASI_GetPerformanceStatistics *) DSO_bind_func(atalla_dso, - ATALLA_F3))) { +#define BINDIT(t, name) (t *)DSO_bind_func(atalla_dso, name) + if ((p1 = BINDIT(tfnASI_GetHardwareConfig, ATALLA_F1)) == NULL + || (p2 = BINDIT(tfnASI_RSAPrivateKeyOpFn, ATALLA_F2)) == NULL + || (p3 = BINDIT(tfnASI_GetPerformanceStatistics, ATALLA_F3)) == NULL) { ATALLAerr(ATALLA_F_ATALLA_INIT, ATALLA_R_NOT_LOADED); goto err; } diff --git a/engines/e_capi.c b/engines/e_capi.c index 33881cdb0b..450f89e8b1 100644 --- a/engines/e_capi.c +++ b/engines/e_capi.c @@ -690,7 +690,7 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY * key) RSA_set_ex_data(rkey, rsa_capi_idx, key); - if (!(ret = EVP_PKEY_new())) + if ((ret = EVP_PKEY_new()) == NULL) goto memerr; EVP_PKEY_assign_RSA(ret, rkey); @@ -735,7 +735,7 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY * key) DSA_set_ex_data(dkey, dsa_capi_idx, key); - if (!(ret = EVP_PKEY_new())) + if ((ret = EVP_PKEY_new()) == NULL) goto memerr; EVP_PKEY_assign_DSA(ret, dkey); @@ -920,7 +920,7 @@ int capi_rsa_priv_dec(int flen, const unsigned char *from, } /* Create temp reverse order version of input */ - if (!(tmpbuf = OPENSSL_malloc(flen))) { + if ((tmpbuf = OPENSSL_malloc(flen)) == NULL) { CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, ERR_R_MALLOC_FAILURE); return -1; } diff --git a/engines/e_chil.c b/engines/e_chil.c index 4a173fc5e4..0764c01db2 100644 --- a/engines/e_chil.c +++ b/engines/e_chil.c @@ -555,26 +555,19 @@ static int hwcrhk_init(ENGINE *e) HWCRHKerr(HWCRHK_F_HWCRHK_INIT, HWCRHK_R_DSO_FAILURE); goto err; } - if (!(p1 = (HWCryptoHook_Init_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_Init)) || - !(p2 = (HWCryptoHook_Finish_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_Finish)) || - !(p3 = (HWCryptoHook_ModExp_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExp)) || + +#define BINDIT(t, name) (t *)DSO_bind_func(hwcrhk_dso, name) + if ((p1 = BINDIT(HWCryptoHook_Init_t, n_hwcrhk_Init)) == NULL + || (p2 = BINDIT(HWCryptoHook_Finish_t, n_hwcrhk_Finish)) == NULL + || (p3 = BINDIT(HWCryptoHook_ModExp_t, n_hwcrhk_ModExp)) == NULL # ifndef OPENSSL_NO_RSA - !(p4 = (HWCryptoHook_RSA_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSA)) || - !(p5 = (HWCryptoHook_RSALoadKey_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSALoadKey)) || - !(p6 = (HWCryptoHook_RSAGetPublicKey_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAGetPublicKey)) || - !(p7 = (HWCryptoHook_RSAUnloadKey_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAUnloadKey)) || + || (p4 = BINDIT(HWCryptoHook_RSA_t, n_hwcrhk_RSA)) == NULL + || (p5 = BINDIT(HWCryptoHook_RSALoadKey_t, n_hwcrhk_RSALoadKey)) == NULL + || (p6 = BINDIT(HWCryptoHook_RSAGetPublicKey_t, n_hwcrhk_RSAGetPublicKey)) == NULL + || (p7 = BINDIT(HWCryptoHook_RSAUnloadKey_t, n_hwcrhk_RSAUnloadKey)) == NULL # endif - !(p8 = (HWCryptoHook_RandomBytes_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_RandomBytes)) || - !(p9 = (HWCryptoHook_ModExpCRT_t *) - DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExpCRT))) { + || (p8 = BINDIT(HWCryptoHook_RandomBytes_t, n_hwcrhk_RandomBytes)) == NULL + || (p9 = BINDIT(HWCryptoHook_ModExpCRT_t, n_hwcrhk_ModExpCRT)) == NULL) { HWCRHKerr(HWCRHK_F_HWCRHK_INIT, HWCRHK_R_DSO_FAILURE); goto err; } diff --git a/engines/e_cswift.c b/engines/e_cswift.c index 5dcee7cdc7..5553794998 100644 --- a/engines/e_cswift.c +++ b/engines/e_cswift.c @@ -404,14 +404,12 @@ static int cswift_init(ENGINE *e) CSWIFTerr(CSWIFT_F_CSWIFT_INIT, CSWIFT_R_NOT_LOADED); goto err; } - if (!(p1 = (t_swAcquireAccContext *) - DSO_bind_func(cswift_dso, CSWIFT_F1)) || - !(p2 = (t_swAttachKeyParam *) - DSO_bind_func(cswift_dso, CSWIFT_F2)) || - !(p3 = (t_swSimpleRequest *) - DSO_bind_func(cswift_dso, CSWIFT_F3)) || - !(p4 = (t_swReleaseAccContext *) - DSO_bind_func(cswift_dso, CSWIFT_F4))) { + +#define BINDIT(t, name) (t *)DSO_bind_func(cswift_dso, name) + if ((p1 = BINDIT(t_swAcquireAccContext, CSWIFT_F1)) == NULL + || (p2 = BINDIT(t_swAttachKeyParam, CSWIFT_F2)) == NULL + || (p3 = BINDIT(t_swSimpleRequest *) DSO_bind_func(cswift_dso, CSWIFT_F3)) == NULL + || (p4 = BINDIT(t_swReleaseAccContext *) DSO_bind_func(cswift_dso, CSWIFT_F4)) == NULL) { CSWIFTerr(CSWIFT_F_CSWIFT_INIT, CSWIFT_R_NOT_LOADED); goto err; } diff --git a/engines/e_sureware.c b/engines/e_sureware.c index 7d8c147db7..fb5e55c930 100644 --- a/engines/e_sureware.c +++ b/engines/e_sureware.c @@ -889,7 +889,7 @@ static int surewarehk_rsa_priv_dec(int flen, const unsigned char *from, ENGINE_R_NOT_INITIALISED); } /* extract ref to private key */ - else if (!(hptr = RSA_get_ex_data(rsa, rsaHndidx))) { + else if ((hptr = RSA_get_ex_data(rsa, rsaHndidx)) == NULL) { SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC, SUREWARE_R_MISSING_KEY_COMPONENTS); goto err; @@ -964,7 +964,7 @@ static int surewarehk_rsa_sign(int flen, const unsigned char *from, SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_SIGN, ENGINE_R_NOT_INITIALISED); } /* extract ref to private key */ - else if (!(hptr = RSA_get_ex_data(rsa, rsaHndidx))) { + else if ((hptr = RSA_get_ex_data(rsa, rsaHndidx)) == NULL) { SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_SIGN, SUREWARE_R_MISSING_KEY_COMPONENTS); } else { @@ -1002,7 +1002,7 @@ static DSA_SIG *surewarehk_dsa_do_sign(const unsigned char *from, int flen, goto err; } /* extract ref to private key */ - else if (!(hptr = DSA_get_ex_data(dsa, dsaHndidx))) { + else if ((hptr = DSA_get_ex_data(dsa, dsaHndidx)) == NULL) { SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN, SUREWARE_R_MISSING_KEY_COMPONENTS); goto err; diff --git a/engines/e_ubsec.c b/engines/e_ubsec.c index a44b0b2b4a..34be930821 100644 --- a/engines/e_ubsec.c +++ b/engines/e_ubsec.c @@ -414,38 +414,26 @@ static int ubsec_init(ENGINE *e) goto err; } - if (!(p1 = (t_UBSEC_ubsec_bytes_to_bits *) - DSO_bind_func(ubsec_dso, UBSEC_F1)) - || !(p2 = (t_UBSEC_ubsec_bits_to_bytes *) - DSO_bind_func(ubsec_dso, UBSEC_F2)) - || !(p3 = (t_UBSEC_ubsec_open *) - DSO_bind_func(ubsec_dso, UBSEC_F3)) - || !(p4 = (t_UBSEC_ubsec_close *) - DSO_bind_func(ubsec_dso, UBSEC_F4)) +#define BINDIT(t, name) (t *)DSO_bind_func(ubsec_dso, name) + if ((p1 = BINDIT(t_UBSEC_ubsec_bytes_to_bits, UBSEC_F1)) == NULL + || (p2 = BINDIT(t_UBSEC_ubsec_bits_to_bytes, UBSEC_F2)) == NULL + || (p3 = BINDIT(t_UBSEC_ubsec_open, UBSEC_F3)) == NULL + || (p4 = BINDIT(t_UBSEC_ubsec_close, UBSEC_F4)) == NULL # ifndef OPENSSL_NO_DH - || !(p5 = (t_UBSEC_diffie_hellman_generate_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F5)) - || !(p6 = (t_UBSEC_diffie_hellman_agree_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F6)) + || (p5 = BINDIT(t_UBSEC_diffie_hellman_generate_ioctl, UBSEC_F5)) == NULL + || (p6 = BINDIT(t_UBSEC_diffie_hellman_agree_ioctl, UBSEC_F6)) == NULL # endif /* #ifndef OPENSSL_NO_RSA */ - || !(p7 = (t_UBSEC_rsa_mod_exp_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F7)) - || !(p8 = (t_UBSEC_rsa_mod_exp_crt_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F8)) + || (p7 = BINDIT(t_UBSEC_rsa_mod_exp_ioctl, UBSEC_F7)) == NULL + || (p8 = BINDIT(t_UBSEC_rsa_mod_exp_crt_ioctl, UBSEC_F8)) == NULL /* #endif */ # ifndef OPENSSL_NO_DSA - || !(p9 = (t_UBSEC_dsa_sign_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F9)) - || !(p10 = (t_UBSEC_dsa_verify_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F10)) + || (p9 = BINDIT(t_UBSEC_dsa_sign_ioctl, UBSEC_F9)) == NULL + || (p10 = BINDIT(t_UBSEC_dsa_verify_ioctl, UBSEC_F10)) == NULL # endif - || !(p11 = (t_UBSEC_math_accelerate_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F11)) - || !(p12 = (t_UBSEC_rng_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F12)) - || !(p13 = (t_UBSEC_max_key_len_ioctl *) - DSO_bind_func(ubsec_dso, UBSEC_F13))) { + || (p11 = BINDIT(t_UBSEC_math_accelerate_ioctl, UBSEC_F11)) == NULL + || (p12 = BINDIT(t_UBSEC_rng_ioctl, UBSEC_F12)) == NULL + || (p13 = BINDIT(t_UBSEC_max_key_len_ioctl, UBSEC_F13)) == NULL) { UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE); goto err; } diff --git a/ssl/d1_srtp.c b/ssl/d1_srtp.c index 9932dde7d2..19cf6ff396 100644 --- a/ssl/d1_srtp.c +++ b/ssl/d1_srtp.c @@ -160,7 +160,7 @@ static int ssl_ctx_make_profiles(const char *profiles_string, char *ptr = (char *)profiles_string; SRTP_PROTECTION_PROFILE *p; - if (!(profiles = sk_SRTP_PROTECTION_PROFILE_new_null())) { + if ((profiles = sk_SRTP_PROTECTION_PROFILE_new_null()) == NULL) { SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES, SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES); return 1; diff --git a/ssl/kssl.c b/ssl/kssl.c index d781042247..15973edc2a 100644 --- a/ssl/kssl.c +++ b/ssl/kssl.c @@ -873,7 +873,8 @@ static size_t *populate_cksumlens(void) # endif /* KRB5_MIT_OLD11 */ # ifdef KRB5CHECKAUTH - if (!cklens && !(cklens = (size_t *)calloc(sizeof(int), n + 1))) + if (cklens == NULL + && (cklens = (size_t *)calloc(sizeof(int), n + 1)) == NULL) return NULL; for (i = 0; i < n; i++) { @@ -911,7 +912,8 @@ unsigned char *kssl_skip_confound(krb5_enctype etype, unsigned char *a) conlen = (etype) ? 8 : 0; - if (!cksumlens && !(cksumlens = populate_cksumlens())) + if (cksumlens NULL + && (cksumlens = populate_cksumlens()) == NULL) return NULL; for (i = 0; (cklen = cksumlens[i]) != 0; i++) { test_auth = a + conlen + cklen; diff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c index 86b7994ca4..85a3ef64cd 100644 --- a/ssl/s3_clnt.c +++ b/ssl/s3_clnt.c @@ -1506,7 +1506,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(s->srp_ctx.N = BN_bin2bn(p, i, NULL))) { + if ((s->srp_ctx.N = BN_bin2bn(p, i, NULL)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } @@ -1526,7 +1526,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(s->srp_ctx.g = BN_bin2bn(p, i, NULL))) { + if ((s->srp_ctx.g = BN_bin2bn(p, i, NULL)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } @@ -1547,7 +1547,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(s->srp_ctx.s = BN_bin2bn(p, i, NULL))) { + if ((s->srp_ctx.s = BN_bin2bn(p, i, NULL)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } @@ -1567,7 +1567,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(s->srp_ctx.B = BN_bin2bn(p, i, NULL))) { + if ((s->srp_ctx.B = BN_bin2bn(p, i, NULL)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } @@ -1623,7 +1623,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(rsa->n = BN_bin2bn(p, i, rsa->n))) { + if ((rsa->n = BN_bin2bn(p, i, rsa->n)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } @@ -1643,7 +1643,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(rsa->e = BN_bin2bn(p, i, rsa->e))) { + if ((rsa->e = BN_bin2bn(p, i, rsa->e)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } @@ -1685,7 +1685,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(dh->p = BN_bin2bn(p, i, NULL))) { + if ((dh->p = BN_bin2bn(p, i, NULL)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } @@ -1705,7 +1705,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(dh->g = BN_bin2bn(p, i, NULL))) { + if ((dh->g = BN_bin2bn(p, i, NULL)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } @@ -1725,7 +1725,7 @@ int ssl3_get_key_exchange(SSL *s) } param_len += i; - if (!(dh->pub_key = BN_bin2bn(p, i, NULL))) { + if ((dh->pub_key = BN_bin2bn(p, i, NULL)) == NULL) { SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c index ec94882aca..2f3158b4ce 100644 --- a/ssl/s3_srvr.c +++ b/ssl/s3_srvr.c @@ -2828,7 +2828,7 @@ int ssl3_get_client_key_exchange(SSL *s) SSL_R_BAD_SRP_A_LENGTH); goto f_err; } - if (!(s->srp_ctx.A = BN_bin2bn(p, i, NULL))) { + if ((s->srp_ctx.A = BN_bin2bn(p, i, NULL)) == NULL) { SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } diff --git a/ssl/tls_srp.c b/ssl/tls_srp.c index 5445f3cbe3..7d4fd1db32 100644 --- a/ssl/tls_srp.c +++ b/ssl/tls_srp.c @@ -340,21 +340,18 @@ int SRP_generate_server_master_secret(SSL *s, unsigned char *master_key) if (!SRP_Verify_A_mod_N(s->srp_ctx.A, s->srp_ctx.N)) goto err; - if (!(u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N))) + if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL) goto err; - if (! - (K = - SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b, - s->srp_ctx.N))) + if ((K = SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b, + s->srp_ctx.N)) == NULL) goto err; tmp_len = BN_num_bytes(K); if ((tmp = OPENSSL_malloc(tmp_len)) == NULL) goto err; BN_bn2bin(K, tmp); - ret = - s->method->ssl3_enc->generate_master_secret(s, master_key, tmp, - tmp_len); + ret = s->method->ssl3_enc->generate_master_secret(s, master_key, tmp, + tmp_len); err: OPENSSL_clear_free(tmp, tmp_len); BN_clear_free(K); @@ -375,7 +372,7 @@ int SRP_generate_client_master_secret(SSL *s, unsigned char *master_key) */ if (SRP_Verify_B_mod_N(s->srp_ctx.B, s->srp_ctx.N) == 0) goto err; - if (!(u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N))) + if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL) goto err; if (s->srp_ctx.SRP_give_srp_client_pwd_callback == NULL) goto err; @@ -384,12 +381,10 @@ int SRP_generate_client_master_secret(SSL *s, unsigned char *master_key) s->srp_ctx.SRP_give_srp_client_pwd_callback(s, s->srp_ctx.SRP_cb_arg))) goto err; - if (!(x = SRP_Calc_x(s->srp_ctx.s, s->srp_ctx.login, passwd))) + if ((x = SRP_Calc_x(s->srp_ctx.s, s->srp_ctx.login, passwd)) == NULL) goto err; - if (! - (K = - SRP_Calc_client_key(s->srp_ctx.N, s->srp_ctx.B, s->srp_ctx.g, x, - s->srp_ctx.a, u))) + if ((K = SRP_Calc_client_key(s->srp_ctx.N, s->srp_ctx.B, s->srp_ctx.g, x, + s->srp_ctx.a, u)) == NULL) goto err; tmp_len = BN_num_bytes(K); diff --git a/test/ectest.c b/test/ectest.c index f04812e0c0..977b8d969b 100644 --- a/test/ectest.c +++ b/test/ectest.c @@ -466,7 +466,7 @@ static void prime_field_tests(void) group_order_tests(group); - if (!(P_160 = EC_GROUP_new(EC_GROUP_method_of(group)))) + if ((P_160 = EC_GROUP_new(EC_GROUP_method_of(group))) == NULL) ABORT; if (!EC_GROUP_copy(P_160, group)) ABORT; @@ -515,7 +515,7 @@ static void prime_field_tests(void) group_order_tests(group); - if (!(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))) + if ((P_192 = EC_GROUP_new(EC_GROUP_method_of(group))) == NULL) ABORT; if (!EC_GROUP_copy(P_192, group)) ABORT; @@ -570,7 +570,7 @@ static void prime_field_tests(void) group_order_tests(group); - if (!(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))) + if ((P_224 = EC_GROUP_new(EC_GROUP_method_of(group))) == NULL) ABORT; if (!EC_GROUP_copy(P_224, group)) ABORT; @@ -630,7 +630,7 @@ static void prime_field_tests(void) group_order_tests(group); - if (!(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))) + if ((P_256 = EC_GROUP_new(EC_GROUP_method_of(group))) == NULL) ABORT; if (!EC_GROUP_copy(P_256, group)) ABORT; @@ -685,7 +685,7 @@ static void prime_field_tests(void) group_order_tests(group); - if (!(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))) + if ((P_384 = EC_GROUP_new(EC_GROUP_method_of(group))) == NULL) ABORT; if (!EC_GROUP_copy(P_384, group)) ABORT; @@ -746,7 +746,7 @@ static void prime_field_tests(void) group_order_tests(group); - if (!(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))) + if ((P_521 = EC_GROUP_new(EC_GROUP_method_of(group))) == NULL) ABORT; if (!EC_GROUP_copy(P_521, group)) ABORT; @@ -916,7 +916,7 @@ static void prime_field_tests(void) if (EC_GROUP_get_degree(group) != _degree) ABORT; \ fprintf(stdout, " ok\n"); \ group_order_tests(group); \ - if (!(_variable = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; \ + if ((_variable = EC_GROUP_new(EC_GROUP_method_of(group))) == NULL) ABORT; \ if (!EC_GROUP_copy(_variable, group)) ABORT; \ # ifndef OPENSSL_NO_EC2M -- 2.25.1