diff options
author | Rich Salz <rsalz@akamai.com> | 2015-05-06 19:43:59 +0200 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-05-11 16:06:38 +0200 |
commit | 75ebbd9aa411c5b8b19ded6ace2b34181566b56a (patch) | |
tree | 6bc9cd77b2794b25f9cd9aac1c66f4626fb975a5 /crypto/pkcs12 | |
parent | Add missing NULL check in X509V3_parse_list() (diff) | |
download | openssl-75ebbd9aa411c5b8b19ded6ace2b34181566b56a.tar.xz openssl-75ebbd9aa411c5b8b19ded6ace2b34181566b56a.zip |
Use p==NULL not !p (in if statements, mainly)
Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'crypto/pkcs12')
-rw-r--r-- | crypto/pkcs12/p12_add.c | 18 | ||||
-rw-r--r-- | crypto/pkcs12/p12_attr.c | 3 | ||||
-rw-r--r-- | crypto/pkcs12/p12_crt.c | 4 | ||||
-rw-r--r-- | crypto/pkcs12/p12_decr.c | 6 | ||||
-rw-r--r-- | crypto/pkcs12/p12_init.c | 5 | ||||
-rw-r--r-- | crypto/pkcs12/p12_kiss.c | 8 | ||||
-rw-r--r-- | crypto/pkcs12/p12_mutl.c | 11 | ||||
-rw-r--r-- | crypto/pkcs12/p12_npas.c | 14 | ||||
-rw-r--r-- | crypto/pkcs12/p12_p8e.c | 4 | ||||
-rw-r--r-- | crypto/pkcs12/p12_utl.c | 6 |
10 files changed, 45 insertions, 34 deletions
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]; |