From: Matt Caswell Date: Fri, 30 Oct 2015 11:12:26 +0000 (+0000) Subject: Continue standardising malloc style for libcrypto X-Git-Tag: OpenSSL_1_1_0-pre1~294 X-Git-Url: https://git.openssl.org/?p=openssl.git;a=commitdiff_plain;h=90945fa31a42dcf3beb90540c618e4d627c595ea Continue standardising malloc style for libcrypto Continuing from previous commit ensure our style is consistent for malloc return checks. Reviewed-by: Kurt Roeckx --- diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c index 46100c32cb..0892976293 100644 --- a/crypto/asn1/a_mbstr.c +++ b/crypto/asn1/a_mbstr.c @@ -200,7 +200,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, } else { free_out = 1; dest = ASN1_STRING_type_new(str_type); - if (!dest) { + if (dest == NULL) { ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE); return -1; } diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c index 80b5055978..cabda53519 100644 --- a/crypto/asn1/a_object.c +++ b/crypto/asn1/a_object.c @@ -139,9 +139,9 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) } if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) { use_bn = 1; - if (!bl) + if (bl == NULL) bl = BN_new(); - if (!bl || !BN_set_word(bl, l)) + if (bl == NULL || !BN_set_word(bl, l)) goto err; } if (use_bn) { @@ -173,7 +173,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) OPENSSL_free(tmp); tmpsize = blsize + 32; tmp = OPENSSL_malloc(tmpsize); - if (!tmp) + if (tmp == NULL) goto err; } while (blsize--) @@ -225,7 +225,7 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) i = i2t_ASN1_OBJECT(buf, sizeof buf, a); if (i > (int)(sizeof(buf) - 1)) { p = OPENSSL_malloc(i + 1); - if (!p) + if (p == NULL) return -1; i2t_ASN1_OBJECT(p, i + 1, a); } diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c index c9d3cea036..7d37c73d39 100644 --- a/crypto/asn1/a_strex.c +++ b/crypto/asn1/a_strex.c @@ -305,7 +305,7 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, t.value.ptr = (char *)str; der_len = i2d_ASN1_TYPE(&t, NULL); der_buf = OPENSSL_malloc(der_len); - if (!der_buf) + if (der_buf == NULL) return -1; p = der_buf; i2d_ASN1_TYPE(&t, &p); diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c index 1c6bbd4061..43252c1cf4 100644 --- a/crypto/asn1/a_strnid.c +++ b/crypto/asn1/a_strnid.c @@ -235,16 +235,16 @@ static ASN1_STRING_TABLE *stable_get(int nid) { ASN1_STRING_TABLE *tmp, *rv; /* Always need a string table so allocate one if NULL */ - if (!stable) { + if (stable == NULL) { stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); - if (!stable) + if (stable == NULL) return NULL; } tmp = ASN1_STRING_TABLE_get(nid); if (tmp && tmp->flags & STABLE_FLAGS_MALLOC) return tmp; rv = OPENSSL_malloc(sizeof(*rv)); - if (!rv) + if (rv == NULL) return NULL; if (!sk_ASN1_STRING_TABLE_push(stable, rv)) { OPENSSL_free(rv); diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c index 2deb67917b..05f0a80da8 100644 --- a/crypto/asn1/ameth_lib.c +++ b/crypto/asn1/ameth_lib.c @@ -224,7 +224,7 @@ int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) { if (app_methods == NULL) { app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); - if (!app_methods) + if (app_methods == NULL) return 0; } if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) @@ -237,7 +237,7 @@ int EVP_PKEY_asn1_add_alias(int to, int from) { EVP_PKEY_ASN1_METHOD *ameth; ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); - if (!ameth) + if (ameth == NULL) return 0; ameth->pkey_base_id = to; if (!EVP_PKEY_asn1_add0(ameth)) { @@ -277,7 +277,7 @@ EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, { EVP_PKEY_ASN1_METHOD *ameth = OPENSSL_zalloc(sizeof(*ameth)); - if (!ameth) + if (ameth == NULL) return NULL; ameth->pkey_id = id; diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c index 5f01b8dac1..200d88d1b2 100644 --- a/crypto/asn1/asn1_gen.c +++ b/crypto/asn1/asn1_gen.c @@ -243,7 +243,7 @@ static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth, /* Allocate buffer for new encoding */ new_der = OPENSSL_malloc(len); - if (!new_der) + if (new_der == NULL) goto err; /* Generate tagged encoding */ diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index ef9223c485..56fd9bf4c3 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -296,7 +296,7 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) if (!str) return NULL; ret = ASN1_STRING_new(); - if (!ret) + if (ret == NULL) return NULL; if (!ASN1_STRING_copy(ret, str)) { ASN1_STRING_free(ret); diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 2a227be5c5..12f6fd67af 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -149,7 +149,7 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, BIO *b64; int r; b64 = BIO_new(BIO_f_base64()); - if (!b64) { + if (b64 == NULL) { ASN1err(ASN1_F_B64_WRITE_ASN1, ERR_R_MALLOC_FAILURE); return 0; } @@ -533,7 +533,7 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) * when streaming as we don't end up with one OCTET STRING per line. */ bf = BIO_new(BIO_f_buffer()); - if (!bf) + if (bf == NULL) return 0; out = BIO_push(bf, out); if (flags & SMIME_BINARY) { @@ -678,7 +678,7 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) int len, state, save_state = 0; headers = sk_MIME_HEADER_new(mime_hdr_cmp); - if (!headers) + if (headers == NULL) return NULL; while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { /* If whitespace at line start then continuation line */ @@ -850,7 +850,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) } } mhdr = OPENSSL_malloc(sizeof(*mhdr)); - if (!mhdr) + if (mhdr == NULL) goto err; mhdr->name = tmpname; mhdr->value = tmpval; @@ -889,7 +889,7 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) } /* Parameter values are case sensitive so leave as is */ mparam = OPENSSL_malloc(sizeof(*mparam)); - if (!mparam) + if (mparam == NULL) goto err; mparam->param_name = tmpname; mparam->param_value = tmpval; diff --git a/crypto/asn1/bio_asn1.c b/crypto/asn1/bio_asn1.c index 910d06f04d..a5bcc265fd 100644 --- a/crypto/asn1/bio_asn1.c +++ b/crypto/asn1/bio_asn1.c @@ -147,7 +147,7 @@ static int asn1_bio_new(BIO *b) { BIO_ASN1_BUF_CTX *ctx; ctx = OPENSSL_malloc(sizeof(*ctx)); - if (!ctx) + if (ctx == NULL) return 0; if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { OPENSSL_free(ctx); @@ -162,7 +162,7 @@ static int asn1_bio_new(BIO *b) static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) { ctx->buf = OPENSSL_malloc(size); - if (!ctx->buf) + if (ctx->buf == NULL) return 0; ctx->bufsize = size; ctx->bufpos = 0; diff --git a/crypto/asn1/bio_ndef.c b/crypto/asn1/bio_ndef.c index ff2fdf529b..dfbbc68986 100644 --- a/crypto/asn1/bio_ndef.c +++ b/crypto/asn1/bio_ndef.c @@ -113,7 +113,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) out = BIO_push(asn_bio, out); - if (!ndef_aux || !asn_bio || !out) + if (ndef_aux == NULL || asn_bio == NULL || !out) goto err; BIO_asn1_set_prefix(asn_bio, ndef_prefix, ndef_prefix_free); @@ -160,7 +160,7 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); p = OPENSSL_malloc(derlen); - if (!p) + if (p == NULL) return 0; ndef_aux->derbuf = p; @@ -229,7 +229,7 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); p = OPENSSL_malloc(derlen); - if (!p) + if (p == NULL) return 0; ndef_aux->derbuf = p; diff --git a/crypto/asn1/p5_pbe.c b/crypto/asn1/p5_pbe.c index cc91fad53b..4d7a9c61c1 100644 --- a/crypto/asn1/p5_pbe.c +++ b/crypto/asn1/p5_pbe.c @@ -82,7 +82,7 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, unsigned char *sstr; pbe = PBEPARAM_new(); - if (!pbe) { + if (pbe == NULL) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); goto err; } @@ -128,7 +128,7 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, { X509_ALGOR *ret; ret = X509_ALGOR_new(); - if (!ret) { + if (ret == NULL) { ASN1err(ASN1_F_PKCS5_PBE_SET, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/asn1/p5_pbev2.c b/crypto/asn1/p5_pbev2.c index 23ed232dd3..ba0c92aca8 100644 --- a/crypto/asn1/p5_pbev2.c +++ b/crypto/asn1/p5_pbev2.c @@ -242,7 +242,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, /* prf can stay NULL if we are using hmacWithSHA1 */ if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) { kdf->prf = X509_ALGOR_new(); - if (!kdf->prf) + if (kdf->prf == NULL) goto merr; X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid), V_ASN1_NULL, NULL); } @@ -250,7 +250,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, /* Finally setup the keyfunc structure */ keyfunc = X509_ALGOR_new(); - if (!keyfunc) + if (keyfunc == NULL) goto merr; keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2); diff --git a/crypto/asn1/p5_scrypt.c b/crypto/asn1/p5_scrypt.c index 3667546634..06bb2ac2c2 100644 --- a/crypto/asn1/p5_scrypt.c +++ b/crypto/asn1/p5_scrypt.c @@ -247,7 +247,7 @@ static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen, /* Finally setup the keyfunc structure */ keyfunc = X509_ALGOR_new(); - if (!keyfunc) + if (keyfunc == NULL) goto merr; keyfunc->algorithm = OBJ_nid2obj(NID_id_scrypt); diff --git a/crypto/asn1/p8_pkey.c b/crypto/asn1/p8_pkey.c index ff55a5bdb0..f4fbc085e7 100644 --- a/crypto/asn1/p8_pkey.c +++ b/crypto/asn1/p8_pkey.c @@ -99,7 +99,7 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int pmtype; ASN1_OCTET_STRING *oct; oct = ASN1_OCTET_STRING_new(); - if (!oct) + if (oct == NULL) return 0; oct->data = penc; ppenc = &oct->data; diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c index 94445bdc49..595c5e4cb1 100644 --- a/crypto/asn1/tasn_dec.c +++ b/crypto/asn1/tasn_dec.c @@ -893,7 +893,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, /* All based on ASN1_STRING and handled the same */ if (!*pval) { stmp = ASN1_STRING_type_new(utype); - if (!stmp) { + if (stmp == NULL) { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c index e2feee0ec3..50375225b0 100644 --- a/crypto/asn1/tasn_enc.c +++ b/crypto/asn1/tasn_enc.c @@ -111,7 +111,7 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, if (len <= 0) return len; buf = OPENSSL_malloc(len); - if (!buf) + if (buf == NULL) return -1; p = buf; ASN1_item_ex_i2d(&val, &p, it, -1, flags); @@ -423,10 +423,10 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, else { derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst)); - if (!derlst) + if (derlst == NULL) return 0; tmpdat = OPENSSL_malloc(skcontlen); - if (!tmpdat) { + if (tmpdat == NULL) { OPENSSL_free(derlst); return 0; } diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c index 6a2ad62d70..668f6419d1 100644 --- a/crypto/asn1/tasn_new.c +++ b/crypto/asn1/tasn_new.c @@ -147,7 +147,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) memset(*pval, 0, it->size); } else { *pval = OPENSSL_zalloc(it->size); - if (!*pval) + if (*pval == NULL) goto memerr; } asn1_set_choice_selector(pval, -1, it); @@ -173,7 +173,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) memset(*pval, 0, it->size); } else { *pval = OPENSSL_zalloc(it->size); - if (!*pval) + if (*pval == NULL) goto memerr; } asn1_do_lock(pval, 0, it); @@ -341,7 +341,7 @@ static int asn1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it, case V_ASN1_ANY: typ = OPENSSL_malloc(sizeof(*typ)); - if (!typ) + if (typ == NULL) return 0; typ->value.ptr = NULL; typ->type = -1; diff --git a/crypto/asn1/tasn_utl.c b/crypto/asn1/tasn_utl.c index 8b62341b9b..10cc1f9143 100644 --- a/crypto/asn1/tasn_utl.c +++ b/crypto/asn1/tasn_utl.c @@ -172,7 +172,7 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, OPENSSL_free(enc->enc); enc->enc = OPENSSL_malloc(inlen); - if (!enc->enc) + if (enc->enc == NULL) return 0; memcpy(enc->enc, in, inlen); enc->len = inlen; diff --git a/crypto/asn1/x_bignum.c b/crypto/asn1/x_bignum.c index d2666e15da..e27480bdfb 100644 --- a/crypto/asn1/x_bignum.c +++ b/crypto/asn1/x_bignum.c @@ -111,7 +111,7 @@ ASN1_ITEM_end(CBIGNUM) static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) { *pval = (ASN1_VALUE *)BN_new(); - if (*pval) + if (*pval != NULL) return 1; else return 0; @@ -120,7 +120,7 @@ static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static int bn_secure_new(ASN1_VALUE **pval, const ASN1_ITEM *it) { *pval = (ASN1_VALUE *)BN_secure_new(); - if (*pval) + if (*pval != NULL) return 1; else return 0; diff --git a/crypto/asn1/x_pkey.c b/crypto/asn1/x_pkey.c index 961b913dc9..cb6f21f0c1 100644 --- a/crypto/asn1/x_pkey.c +++ b/crypto/asn1/x_pkey.c @@ -67,13 +67,13 @@ X509_PKEY *X509_PKEY_new(void) X509_PKEY *ret = NULL; ret = OPENSSL_zalloc(sizeof(*ret)); - if (!ret) + if (ret == NULL) goto err; ret->references = 1; ret->enc_algor = X509_ALGOR_new(); ret->enc_pkey = ASN1_OCTET_STRING_new(); - if (!ret->enc_algor || !ret->enc_pkey) + if (ret->enc_algor == NULL || ret->enc_pkey == NULL) goto err; return ret; diff --git a/crypto/asn1/x_pubkey.c b/crypto/asn1/x_pubkey.c index b2d81dfcc1..d20019005c 100644 --- a/crypto/asn1/x_pubkey.c +++ b/crypto/asn1/x_pubkey.c @@ -246,7 +246,7 @@ int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) if (!a) return 0; pktmp = EVP_PKEY_new(); - if (!pktmp) { + if (pktmp == NULL) { ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); return 0; } @@ -286,7 +286,7 @@ int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) if (!a) return 0; pktmp = EVP_PKEY_new(); - if (!pktmp) { + if (pktmp == NULL) { ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c index f49ebee436..f82b0781cc 100644 --- a/crypto/bio/b_print.c +++ b/crypto/bio/b_print.c @@ -711,7 +711,7 @@ doapr_outch(char **sbuffer, *maxlen += 1024; if (*buffer == NULL) { *buffer = OPENSSL_malloc(*maxlen); - if (!*buffer) { + if (*buffer == NULL) { /* Panic! Can't really do anything sensible. Just return */ return; } diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c index 9c6af4bc9d..0975856d59 100644 --- a/crypto/bio/bss_dgram.c +++ b/crypto/bio/bss_dgram.c @@ -997,7 +997,7 @@ BIO *BIO_new_dgram_sctp(int fd, int close_flag) */ sockopt_len = (socklen_t) (sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t)); authchunks = OPENSSL_zalloc(sockopt_len); - if (!authchunks) { + if (authchunks == NULL) { BIO_vfree(bio); return (NULL); } @@ -1334,7 +1334,7 @@ static int dgram_sctp_read(BIO *b, char *out, int outl) optlen = (socklen_t) (sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t)); authchunks = OPENSSL_malloc(optlen); - if (!authchunks) { + if (authchunks == NULL) { BIOerr(BIO_F_DGRAM_SCTP_READ, ERR_R_MALLOC_FAILURE); return -1; } diff --git a/crypto/bn/bn_ctx.c b/crypto/bn/bn_ctx.c index 756d404c13..19ff68e1eb 100644 --- a/crypto/bn/bn_ctx.c +++ b/crypto/bn/bn_ctx.c @@ -204,7 +204,7 @@ BN_CTX *BN_CTX_secure_new(void) { BN_CTX *ret = BN_CTX_new(); - if (ret) + if (ret != NULL) ret->flags = BN_FLG_SECURE; return ret; } diff --git a/crypto/bn/bn_intern.c b/crypto/bn/bn_intern.c index 0b222517d4..abc8fc45a1 100644 --- a/crypto/bn/bn_intern.c +++ b/crypto/bn/bn_intern.c @@ -74,7 +74,7 @@ signed char *bn_compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len) if (BN_is_zero(scalar)) { r = OPENSSL_malloc(1); - if (!r) { + if (r == NULL) { BNerr(BN_F_BN_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c index 3b07d7d28c..2042920d35 100644 --- a/crypto/bn/bn_lib.c +++ b/crypto/bn/bn_lib.c @@ -287,7 +287,7 @@ BIGNUM *BN_new(void) BIGNUM *BN_secure_new(void) { BIGNUM *ret = BN_new(); - if (ret) + if (ret != NULL) ret->flags |= BN_FLG_SECURE; return (ret); } diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c index d4d817a74f..bda2157aa5 100644 --- a/crypto/bn/bn_mont.c +++ b/crypto/bn/bn_mont.c @@ -517,7 +517,7 @@ BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock, * (the losers throw away the work they've done). */ ret = BN_MONT_CTX_new(); - if (!ret) + if (ret == NULL) return NULL; if (!BN_MONT_CTX_set(ret, mod, ctx)) { BN_MONT_CTX_free(ret); diff --git a/crypto/bn/bn_rand.c b/crypto/bn/bn_rand.c index 2764c8a307..66a175c32a 100644 --- a/crypto/bn/bn_rand.c +++ b/crypto/bn/bn_rand.c @@ -315,7 +315,7 @@ int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range, int ret = 0; k_bytes = OPENSSL_malloc(num_k_bytes); - if (!k_bytes) + if (k_bytes == NULL) goto err; /* We copy |priv| into a local buffer to avoid exposing its length. */ diff --git a/crypto/cmac/cm_pmeth.c b/crypto/cmac/cm_pmeth.c index 22c7dbee06..080db6329e 100644 --- a/crypto/cmac/cm_pmeth.c +++ b/crypto/cmac/cm_pmeth.c @@ -64,7 +64,7 @@ static int pkey_cmac_init(EVP_PKEY_CTX *ctx) { ctx->data = CMAC_CTX_new(); - if (!ctx->data) + if (ctx->data == NULL) return 0; ctx->keygen_info_count = 0; return 1; @@ -88,7 +88,7 @@ static int pkey_cmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) { CMAC_CTX *cmkey = CMAC_CTX_new(); CMAC_CTX *cmctx = ctx->data; - if (!cmkey) + if (cmkey == NULL) return 0; if (!CMAC_CTX_copy(cmkey, cmctx)) { CMAC_CTX_free(cmkey); diff --git a/crypto/cmac/cmac.c b/crypto/cmac/cmac.c index 0711bffd8a..fc9e761266 100644 --- a/crypto/cmac/cmac.c +++ b/crypto/cmac/cmac.c @@ -92,7 +92,7 @@ CMAC_CTX *CMAC_CTX_new(void) CMAC_CTX *ctx; ctx = OPENSSL_malloc(sizeof(*ctx)); - if (!ctx) + if (ctx == NULL) return NULL; EVP_CIPHER_CTX_init(&ctx->cctx); ctx->nlast_block = -1; diff --git a/crypto/cms/cms_cd.c b/crypto/cms/cms_cd.c index 81cc6c51d5..1b84309efb 100644 --- a/crypto/cms/cms_cd.c +++ b/crypto/cms/cms_cd.c @@ -82,12 +82,12 @@ CMS_ContentInfo *cms_CompressedData_create(int comp_nid) return NULL; } cms = CMS_ContentInfo_new(); - if (!cms) + if (cms == NULL) return NULL; cd = M_ASN1_new_of(CMS_CompressedData); - if (!cd) + if (cd == NULL) goto err; cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData); diff --git a/crypto/cms/cms_dd.c b/crypto/cms/cms_dd.c index 7609b6f8d4..426f8cd74c 100644 --- a/crypto/cms/cms_dd.c +++ b/crypto/cms/cms_dd.c @@ -67,12 +67,12 @@ CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md) CMS_ContentInfo *cms; CMS_DigestedData *dd; cms = CMS_ContentInfo_new(); - if (!cms) + if (cms == NULL) return NULL; dd = M_ASN1_new_of(CMS_DigestedData); - if (!dd) + if (dd == NULL) goto err; cms->contentType = OBJ_nid2obj(NID_pkcs7_digest); diff --git a/crypto/cms/cms_enc.c b/crypto/cms/cms_enc.c index fc66f60060..a16120fc72 100644 --- a/crypto/cms/cms_enc.c +++ b/crypto/cms/cms_enc.c @@ -82,7 +82,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) enc = ec->cipher ? 1 : 0; b = BIO_new(BIO_f_cipher()); - if (!b) { + if (b == NULL) { CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); return NULL; } @@ -130,7 +130,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) /* Generate random session key */ if (!enc || !ec->key) { tkey = OPENSSL_malloc(tkeylen); - if (!tkey) { + if (tkey == NULL) { CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); goto err; } @@ -179,7 +179,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec) if (piv) { calg->parameter = ASN1_TYPE_new(); - if (!calg->parameter) { + if (calg->parameter == NULL) { CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, ERR_R_MALLOC_FAILURE); goto err; } @@ -210,7 +210,7 @@ int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec, ec->cipher = cipher; if (key) { ec->key = OPENSSL_malloc(keylen); - if (!ec->key) + if (ec->key == NULL) return 0; memcpy(ec->key, key, keylen); } diff --git a/crypto/cms/cms_env.c b/crypto/cms/cms_env.c index e133bcc6a7..b9775e0ad2 100644 --- a/crypto/cms/cms_env.c +++ b/crypto/cms/cms_env.c @@ -153,10 +153,10 @@ CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher) CMS_ContentInfo *cms; CMS_EnvelopedData *env; cms = CMS_ContentInfo_new(); - if (!cms) + if (cms == NULL) goto merr; env = cms_enveloped_data_init(cms); - if (!env) + if (env == NULL) goto merr; if (!cms_EncryptedContent_init(env->encryptedContentInfo, cipher, NULL, 0)) @@ -208,7 +208,7 @@ static int cms_RecipientInfo_ktri_init(CMS_RecipientInfo *ri, X509 *recip, if (flags & CMS_KEY_PARAM) { ktri->pctx = EVP_PKEY_CTX_new(ktri->pkey, NULL); - if (!ktri->pctx) + if (ktri->pctx == NULL) return 0; if (EVP_PKEY_encrypt_init(ktri->pctx) <= 0) return 0; @@ -362,7 +362,7 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms, goto err; } else { pctx = EVP_PKEY_CTX_new(ktri->pkey, NULL); - if (!pctx) + if (pctx == NULL) return 0; if (EVP_PKEY_encrypt_init(pctx) <= 0) @@ -420,7 +420,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, } ktri->pctx = EVP_PKEY_CTX_new(pkey, NULL); - if (!ktri->pctx) + if (ktri->pctx == NULL) return 0; if (EVP_PKEY_decrypt_init(ktri->pctx) <= 0) @@ -685,7 +685,7 @@ static int cms_RecipientInfo_kekri_encrypt(CMS_ContentInfo *cms, wkey = OPENSSL_malloc(ec->keylen + 8); - if (!wkey) { + if (wkey == NULL) { CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -755,7 +755,7 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms, ukey = OPENSSL_malloc(kekri->encryptedKey->length - 8); - if (!ukey) { + if (ukey == NULL) { CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/cms/cms_ess.c b/crypto/cms/cms_ess.c index 2149749983..3e35d060d9 100644 --- a/crypto/cms/cms_ess.c +++ b/crypto/cms/cms_ess.c @@ -97,7 +97,7 @@ CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen, CMS_ReceiptRequest *rr = NULL; rr = CMS_ReceiptRequest_new(); - if (!rr) + if (rr == NULL) goto merr; if (id) ASN1_STRING_set0(rr->signedContentIdentifier, id, idlen); diff --git a/crypto/cms/cms_io.c b/crypto/cms/cms_io.c index 084a2cc15c..1d1d432153 100644 --- a/crypto/cms/cms_io.c +++ b/crypto/cms/cms_io.c @@ -63,11 +63,11 @@ int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms) { ASN1_OCTET_STRING **pos; pos = CMS_get0_content(cms); - if (!pos) + if (pos == NULL) return 0; - if (!*pos) + if (*pos == NULL) *pos = ASN1_OCTET_STRING_new(); - if (*pos) { + if (*pos != NULL) { (*pos)->flags |= ASN1_STRING_FLAG_NDEF; (*pos)->flags &= ~ASN1_STRING_FLAG_CONT; *boundary = &(*pos)->data; diff --git a/crypto/cms/cms_kari.c b/crypto/cms/cms_kari.c index 77181bc775..c6d45a0c2a 100644 --- a/crypto/cms/cms_kari.c +++ b/crypto/cms/cms_kari.c @@ -252,7 +252,7 @@ static int cms_kek_cipher(unsigned char **pout, size_t *poutlen, if (!EVP_CipherUpdate(&kari->ctx, NULL, &outlen, in, inlen)) goto err; out = OPENSSL_malloc(outlen); - if (!out) + if (out == NULL) goto err; if (!EVP_CipherUpdate(&kari->ctx, out, &outlen, in, inlen)) goto err; diff --git a/crypto/cms/cms_lib.c b/crypto/cms/cms_lib.c index 157590d845..fdc69f6f8f 100644 --- a/crypto/cms/cms_lib.c +++ b/crypto/cms/cms_lib.c @@ -76,7 +76,7 @@ CMS_ContentInfo *cms_Data_create(void) { CMS_ContentInfo *cms; cms = CMS_ContentInfo_new(); - if (cms) { + if (cms != NULL) { cms->contentType = OBJ_nid2obj(NID_pkcs7_data); /* Never detached */ CMS_set_detached(cms, 0); @@ -316,9 +316,9 @@ int CMS_set_detached(CMS_ContentInfo *cms, int detached) *pos = NULL; return 1; } - if (!*pos) + if (*pos == NULL) *pos = ASN1_OCTET_STRING_new(); - if (*pos) { + if (*pos != NULL) { /* * NB: special flag to show content is created and not read in. */ @@ -344,7 +344,7 @@ BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm) goto err; } mdbio = BIO_new(BIO_f_md()); - if (!mdbio || !BIO_set_md(mdbio, digest)) { + if (mdbio == NULL || !BIO_set_md(mdbio, digest)) { CMSerr(CMS_F_CMS_DIGESTALGORITHM_INIT_BIO, CMS_R_MD_BIO_INIT_ERROR); goto err; } diff --git a/crypto/cms/cms_pwri.c b/crypto/cms/cms_pwri.c index f722d9a9b6..d662938768 100644 --- a/crypto/cms/cms_pwri.c +++ b/crypto/cms/cms_pwri.c @@ -121,6 +121,9 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms, /* Setup algorithm identifier for cipher */ encalg = X509_ALGOR_new(); + if (encalg == NULL) { + goto merr; + } EVP_CIPHER_CTX_init(&ctx); if (EVP_EncryptInit_ex(&ctx, kekciph, NULL, NULL, NULL) <= 0) { @@ -155,11 +158,11 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms, /* Initialize recipient info */ ri = M_ASN1_new_of(CMS_RecipientInfo); - if (!ri) + if (ri == NULL) goto merr; ri->d.pwri = M_ASN1_new_of(CMS_PasswordRecipientInfo); - if (!ri->d.pwri) + if (ri->d.pwri == NULL) goto merr; ri->type = CMS_RECIPINFO_PASS; @@ -167,11 +170,11 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms, /* Since this is overwritten, free up empty structure already there */ X509_ALGOR_free(pwri->keyEncryptionAlgorithm); pwri->keyEncryptionAlgorithm = X509_ALGOR_new(); - if (!pwri->keyEncryptionAlgorithm) + if (pwri->keyEncryptionAlgorithm == NULL) goto merr; pwri->keyEncryptionAlgorithm->algorithm = OBJ_nid2obj(wrap_nid); pwri->keyEncryptionAlgorithm->parameter = ASN1_TYPE_new(); - if (!pwri->keyEncryptionAlgorithm->parameter) + if (pwri->keyEncryptionAlgorithm->parameter == NULL) goto merr; if (!ASN1_item_pack(encalg, ASN1_ITEM_rptr(X509_ALGOR), @@ -230,7 +233,7 @@ static int kek_unwrap_key(unsigned char *out, size_t *outlen, return 0; } tmp = OPENSSL_malloc(inlen); - if (!tmp) + if (tmp == NULL) return 0; /* setup IV by decrypting last two blocks */ if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl, @@ -388,7 +391,7 @@ int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri, key = OPENSSL_malloc(keylen); - if (!key) + if (key == NULL) goto err; if (!kek_wrap_key(key, &keylen, ec->key, ec->keylen, &kekctx)) @@ -398,7 +401,7 @@ int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri, } else { key = OPENSSL_malloc(pwri->encryptedKey->length); - if (!key) { + if (key == NULL) { CMSerr(CMS_F_CMS_RECIPIENTINFO_PWRI_CRYPT, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/cms/cms_sd.c b/crypto/cms/cms_sd.c index 50064e286c..1720bcd870 100644 --- a/crypto/cms/cms_sd.c +++ b/crypto/cms/cms_sd.c @@ -332,7 +332,7 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, if (i == sk_X509_ALGOR_num(sd->digestAlgorithms)) { alg = X509_ALGOR_new(); - if (!alg) + if (alg == NULL) goto merr; X509_ALGOR_set_md(alg, md); if (!sk_X509_ALGOR_push(sd->digestAlgorithms, alg)) { @@ -381,7 +381,7 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, if (flags & CMS_KEY_PARAM) { if (flags & CMS_NOATTR) { si->pctx = EVP_PKEY_CTX_new(si->pkey, NULL); - if (!si->pctx) + if (si->pctx == NULL) goto err; if (EVP_PKEY_sign_init(si->pctx) <= 0) goto err; @@ -617,7 +617,7 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms, goto err; siglen = EVP_PKEY_size(si->pkey); sig = OPENSSL_malloc(siglen); - if (!sig) { + if (sig == NULL) { CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, ERR_R_MALLOC_FAILURE); goto err; } @@ -630,7 +630,7 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms, unsigned char *sig; unsigned int siglen; sig = OPENSSL_malloc(EVP_PKEY_size(si->pkey)); - if (!sig) { + if (sig == NULL) { CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, ERR_R_MALLOC_FAILURE); goto err; } @@ -708,7 +708,7 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si) goto err; OPENSSL_free(abuf); abuf = OPENSSL_malloc(siglen); - if (!abuf) + if (abuf == NULL) goto err; if (EVP_DigestSignFinal(mctx, abuf, &siglen) <= 0) goto err; @@ -851,6 +851,8 @@ int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain) } else { const EVP_MD *md = EVP_MD_CTX_md(&mctx); pkctx = EVP_PKEY_CTX_new(si->pkey, NULL); + if (pkctx == NULL) + goto err; if (EVP_PKEY_verify_init(pkctx) <= 0) goto err; if (EVP_PKEY_CTX_set_signature_md(pkctx, md) <= 0) @@ -894,20 +896,20 @@ int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs, ASN1_INTEGER *key = NULL; if (keysize > 0) { key = ASN1_INTEGER_new(); - if (!key || !ASN1_INTEGER_set(key, keysize)) + if (key == NULL || !ASN1_INTEGER_set(key, keysize)) return 0; } alg = X509_ALGOR_new(); - if (!alg) { + if (alg == NULL) { ASN1_INTEGER_free(key); return 0; } X509_ALGOR_set0(alg, OBJ_nid2obj(algnid), key ? V_ASN1_INTEGER : V_ASN1_UNDEF, key); - if (!*algs) + if (*algs == NULL) *algs = sk_X509_ALGOR_new_null(); - if (!*algs || !sk_X509_ALGOR_push(*algs, alg)) { + if (*algs == NULL || !sk_X509_ALGOR_push(*algs, alg)) { X509_ALGOR_free(alg); return 0; } diff --git a/crypto/cms/cms_smime.c b/crypto/cms/cms_smime.c index 6bed211384..5b55f055f7 100644 --- a/crypto/cms/cms_smime.c +++ b/crypto/cms/cms_smime.c @@ -82,7 +82,7 @@ static int cms_copy_content(BIO *out, BIO *in, unsigned int flags) tmpout = cms_get_text_bio(out, flags); - if (!tmpout) { + if (tmpout == NULL) { CMSerr(CMS_F_CMS_COPY_CONTENT, ERR_R_MALLOC_FAILURE); goto err; } @@ -253,7 +253,7 @@ CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, return NULL; } cms = CMS_ContentInfo_new(); - if (!cms) + if (cms == NULL) return NULL; if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) return NULL; @@ -482,7 +482,7 @@ CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, int i; cms = CMS_ContentInfo_new(); - if (!cms || !CMS_SignedData_init(cms)) + if (cms == NULL || !CMS_SignedData_init(cms)) goto merr; if (flags & CMS_ASCIICRLF && !CMS_set1_eContentType(cms, diff --git a/crypto/comp/c_zlib.c b/crypto/comp/c_zlib.c index ea01ba46e5..6307dafeb6 100644 --- a/crypto/comp/c_zlib.c +++ b/crypto/comp/c_zlib.c @@ -364,7 +364,7 @@ static int bio_zlib_new(BIO *bi) } # endif ctx = OPENSSL_zalloc(sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE); return 0; } @@ -416,7 +416,7 @@ static int bio_zlib_read(BIO *b, char *out, int outl) BIO_clear_retry_flags(b); if (!ctx->ibuf) { ctx->ibuf = OPENSSL_malloc(ctx->ibufsize); - if (!ctx->ibuf) { + if (ctx->ibuf == NULL) { COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE); return 0; } @@ -475,7 +475,7 @@ static int bio_zlib_write(BIO *b, const char *in, int inl) if (!ctx->obuf) { ctx->obuf = OPENSSL_malloc(ctx->obufsize); /* Need error here */ - if (!ctx->obuf) { + if (ctx->obuf == NULL) { COMPerr(COMP_F_BIO_ZLIB_WRITE, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c index 1da68f9334..1ff49aa281 100644 --- a/crypto/conf/conf_def.c +++ b/crypto/conf/conf_def.c @@ -129,7 +129,7 @@ static CONF *def_create(CONF_METHOD *meth) CONF *ret; ret = OPENSSL_malloc(sizeof(*ret)); - if (ret) + if (ret != NULL) if (meth->init(ret) == 0) { OPENSSL_free(ret); ret = NULL; diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c index c23a0f6a46..c1fbb601d5 100644 --- a/crypto/conf/conf_mod.c +++ b/crypto/conf/conf_mod.c @@ -166,7 +166,7 @@ int CONF_modules_load_file(const char *filename, const char *appname, CONF *conf = NULL; int ret = 0; conf = NCONF_new(NULL); - if (!conf) + if (conf == NULL) goto err; if (filename == NULL) { @@ -336,7 +336,7 @@ static int module_init(CONF_MODULE *pmod, char *name, char *value, /* Otherwise add initialized module to list */ imod = OPENSSL_malloc(sizeof(*imod)); - if (!imod) + if (imod == NULL) goto err; imod->pmod = pmod; @@ -535,7 +535,7 @@ char *CONF_get1_default_config_file(void) file = OPENSSL_malloc(len + 1); - if (!file) + if (file == NULL) return NULL; BUF_strlcpy(file, X509_get_default_cert_area(), len + 1); #ifndef OPENSSL_SYS_VMS diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index f0fcd83c52..43cba87a1e 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -156,7 +156,7 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) dh = pkey->pkey.dh; str = ASN1_STRING_new(); - if (!str) { + if (str == NULL) { DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); goto err; } @@ -258,7 +258,7 @@ static int dh_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) params = ASN1_STRING_new(); - if (!params) { + if (params == NULL) { DHerr(DH_F_DH_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); goto err; } @@ -496,7 +496,7 @@ DH *DHparams_dup(DH *dh) { DH *ret; ret = DH_new(); - if (!ret) + if (ret == NULL) return NULL; if (!int_dh_param_copy(ret, dh, -1)) { DH_free(ret); @@ -691,7 +691,7 @@ static int dh_cms_set_peerkey(EVP_PKEY_CTX *pctx, } pkpeer = EVP_PKEY_new(); - if (!pkpeer) + if (pkpeer == NULL) goto err; EVP_PKEY_assign(pkpeer, pk->ameth->pkey_id, dhpeer); dhpeer = NULL; @@ -891,11 +891,11 @@ static int dh_cms_encrypt(CMS_RecipientInfo *ri) /* Package wrap algorithm in an AlgorithmIdentifier */ wrap_alg = X509_ALGOR_new(); - if (!wrap_alg) + if (wrap_alg == NULL) goto err; wrap_alg->algorithm = OBJ_nid2obj(wrap_nid); wrap_alg->parameter = ASN1_TYPE_new(); - if (!wrap_alg->parameter) + if (wrap_alg->parameter == NULL) goto err; if (EVP_CIPHER_param_to_asn1(ctx, wrap_alg->parameter) <= 0) goto err; @@ -927,7 +927,7 @@ static int dh_cms_encrypt(CMS_RecipientInfo *ri) if (!penc || !penclen) goto err; wrap_str = ASN1_STRING_new(); - if (!wrap_str) + if (wrap_str == NULL) goto err; ASN1_STRING_set0(wrap_str, penc, penclen); penc = NULL; diff --git a/crypto/dh/dh_asn1.c b/crypto/dh/dh_asn1.c index cc307dc2df..860feaaf9c 100644 --- a/crypto/dh/dh_asn1.c +++ b/crypto/dh/dh_asn1.c @@ -70,7 +70,7 @@ static int dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, { if (operation == ASN1_OP_NEW_PRE) { *pval = (ASN1_VALUE *)DH_new(); - if (*pval) + if (*pval != NULL) return 2; return 0; } else if (operation == ASN1_OP_FREE_PRE) { @@ -133,10 +133,10 @@ DH *d2i_DHxparams(DH **a, const unsigned char **pp, long length) int_dhx942_dh *dhx = NULL; DH *dh = NULL; dh = DH_new(); - if (!dh) + if (dh == NULL) return NULL; dhx = d2i_int_dhx(NULL, pp, length); - if (!dhx) { + if (dhx == NULL) { DH_free(dh); return NULL; } diff --git a/crypto/dh/dh_depr.c b/crypto/dh/dh_depr.c index 7be6041dc8..de93472189 100644 --- a/crypto/dh/dh_depr.c +++ b/crypto/dh/dh_depr.c @@ -72,7 +72,7 @@ DH *DH_generate_parameters(int prime_len, int generator, if ((ret = DH_new()) == NULL) return NULL; cb = BN_GENCB_new(); - if (!cb) { + if (cb == NULL) { DH_free(ret); return NULL; } diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index b6c3038976..a5cac063ab 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -167,6 +167,8 @@ static int generate_key(DH *dh) if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) { local_prk = prk = BN_new(); + if (local_prk == NULL) + goto err; BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); } else prk = priv_key; diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index ff27221644..1e12c3e9a7 100644 --- a/crypto/dh/dh_pmeth.c +++ b/crypto/dh/dh_pmeth.c @@ -100,7 +100,7 @@ static int pkey_dh_init(EVP_PKEY_CTX *ctx) DH_PKEY_CTX *dctx; dctx = OPENSSL_zalloc(sizeof(*dctx)); - if (!dctx) + if (dctx == NULL) return 0; dctx->prime_len = 1024; dctx->subprime_len = -1; @@ -312,7 +312,7 @@ static DSA *dsa_dh_generate(DH_PKEY_CTX *dctx, BN_GENCB *pcb) if (dctx->use_dsa > 2) return NULL; ret = DSA_new(); - if (!ret) + if (ret == NULL) return NULL; if (subprime_len == -1) { if (prime_len >= 2048) @@ -370,6 +370,8 @@ static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) if (ctx->pkey_gencb) { pcb = BN_GENCB_new(); + if (pcb == NULL) + return 0; evp_pkey_set_cb_translate(pcb, ctx); } else pcb = NULL; @@ -378,7 +380,7 @@ static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) DSA *dsa_dh; dsa_dh = dsa_dh_generate(dctx, pcb); BN_GENCB_free(pcb); - if (!dsa_dh) + if (dsa_dh == NULL) return 0; dh = DSA_dup_DH(dsa_dh); DSA_free(dsa_dh); @@ -389,7 +391,7 @@ static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) } #endif dh = DH_new(); - if (!dh) { + if (dh == NULL) { BN_GENCB_free(pcb); return 0; } @@ -411,7 +413,7 @@ static int pkey_dh_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return 0; } dh = DH_new(); - if (!dh) + if (dh == NULL) return 0; EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, dh); /* Note: if error return, pkey is freed by parent routine */ @@ -460,7 +462,7 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key, ret = 0; Zlen = DH_size(dh); Z = OPENSSL_malloc(Zlen); - if (!Z) { + if (Z == NULL) { goto err; } if (DH_compute_key_padded(Z, dhpub, dh) <= 0) diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index 0002e0810e..d1d32c6959 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -136,7 +136,7 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) dsa = pkey->pkey.dsa; if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) { str = ASN1_STRING_new(); - if (!str) { + if (str == NULL) { DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE); goto err; } @@ -298,7 +298,7 @@ static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) params = ASN1_STRING_new(); - if (!params) { + if (params == NULL) { DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/dsa/dsa_asn1.c b/crypto/dsa/dsa_asn1.c index 99bca3b260..5225a389e6 100644 --- a/crypto/dsa/dsa_asn1.c +++ b/crypto/dsa/dsa_asn1.c @@ -71,7 +71,7 @@ static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, if (operation == ASN1_OP_NEW_PRE) { DSA_SIG *sig; sig = OPENSSL_malloc(sizeof(*sig)); - if (!sig) { + if (sig == NULL) { DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE); return 0; } @@ -96,7 +96,7 @@ static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, { if (operation == ASN1_OP_NEW_PRE) { *pval = (ASN1_VALUE *)DSA_new(); - if (*pval) + if (*pval != NULL) return 2; return 0; } else if (operation == ASN1_OP_FREE_PRE) { diff --git a/crypto/dsa/dsa_depr.c b/crypto/dsa/dsa_depr.c index f14e587646..0b18776845 100644 --- a/crypto/dsa/dsa_depr.c +++ b/crypto/dsa/dsa_depr.c @@ -89,7 +89,7 @@ DSA *DSA_generate_parameters(int bits, if ((ret = DSA_new()) == NULL) return NULL; cb = BN_GENCB_new(); - if (!cb) + if (cb == NULL) goto err; BN_GENCB_set_old(cb, callback, cb_arg); diff --git a/crypto/dsa/dsa_gen.c b/crypto/dsa/dsa_gen.c index 480c29dbae..106ec3cb5f 100644 --- a/crypto/dsa/dsa_gen.c +++ b/crypto/dsa/dsa_gen.c @@ -387,7 +387,7 @@ int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N, else seed_tmp = OPENSSL_malloc(seed_len); - if (!seed || !seed_tmp) + if (seed == NULL || seed_tmp == NULL) goto err; if (seed_in) @@ -650,7 +650,7 @@ int dsa_paramgen_check_g(DSA *dsa) BN_MONT_CTX *mont = NULL; int rv = -1; ctx = BN_CTX_new(); - if (!ctx) + if (ctx == NULL) return -1; BN_CTX_start(ctx); if (BN_cmp(dsa->g, BN_value_one()) <= 0) diff --git a/crypto/dsa/dsa_key.c b/crypto/dsa/dsa_key.c index 19d21eacf7..d27d47a3b8 100644 --- a/crypto/dsa/dsa_key.c +++ b/crypto/dsa/dsa_key.c @@ -104,7 +104,7 @@ static int dsa_builtin_keygen(DSA *dsa) if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) { local_prk = prk = BN_new(); - if (!local_prk) + if (local_prk == NULL) goto err; BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); } else diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c index 19a75834fb..34b4a4ea4a 100644 --- a/crypto/dsa/dsa_ossl.c +++ b/crypto/dsa/dsa_ossl.c @@ -144,7 +144,7 @@ static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) m = BN_new(); xr = BN_new(); - if (!m || !xr) + if (m == NULL || xr == NULL) goto err; if (!dsa->p || !dsa->q || !dsa->g) { @@ -242,7 +242,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, k = BN_new(); kq = BN_new(); - if (!k || !kq) + if (k == NULL || kq == NULL) goto err; if (ctx_in == NULL) { @@ -356,7 +356,7 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, u2 = BN_new(); t1 = BN_new(); ctx = BN_CTX_new(); - if (!u1 || !u2 || !t1 || !ctx) + if (u1 == NULL || u2 == NULL || t1 == NULL || ctx == NULL) goto err; if (BN_is_zero(sig->r) || BN_is_negative(sig->r) || diff --git a/crypto/dsa/dsa_pmeth.c b/crypto/dsa/dsa_pmeth.c index 1adab4f8ec..1110e01b39 100644 --- a/crypto/dsa/dsa_pmeth.c +++ b/crypto/dsa/dsa_pmeth.c @@ -82,7 +82,7 @@ static int pkey_dsa_init(EVP_PKEY_CTX *ctx) { DSA_PKEY_CTX *dctx; dctx = OPENSSL_malloc(sizeof(*dctx)); - if (!dctx) + if (dctx == NULL) return 0; dctx->nbits = 1024; dctx->qbits = 160; @@ -255,13 +255,13 @@ static int pkey_dsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) int ret; if (ctx->pkey_gencb) { pcb = BN_GENCB_new(); - if (!pcb) + if (pcb == NULL) return 0; evp_pkey_set_cb_translate(pcb, ctx); } else pcb = NULL; dsa = DSA_new(); - if (!dsa) { + if (dsa == NULL) { BN_GENCB_free(pcb); return 0; } @@ -283,7 +283,7 @@ static int pkey_dsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return 0; } dsa = DSA_new(); - if (!dsa) + if (dsa == NULL) return 0; EVP_PKEY_assign_DSA(pkey, dsa); /* Note: if error return, pkey is freed by parent routine */ diff --git a/crypto/dsa/dsa_prn.c b/crypto/dsa/dsa_prn.c index 64c51fced1..d1aef75b0f 100644 --- a/crypto/dsa/dsa_prn.c +++ b/crypto/dsa/dsa_prn.c @@ -99,7 +99,7 @@ int DSA_print(BIO *bp, const DSA *x, int off) EVP_PKEY *pk; int ret; pk = EVP_PKEY_new(); - if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x)) + if (pk == NULL || !EVP_PKEY_set1_DSA(pk, (DSA *)x)) return 0; ret = EVP_PKEY_print_private(bp, pk, off, NULL); EVP_PKEY_free(pk); @@ -111,7 +111,7 @@ int DSAparams_print(BIO *bp, const DSA *x) EVP_PKEY *pk; int ret; pk = EVP_PKEY_new(); - if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x)) + if (pk == NULL || !EVP_PKEY_set1_DSA(pk, (DSA *)x)) return 0; ret = EVP_PKEY_print_params(bp, pk, 4, NULL); EVP_PKEY_free(pk); diff --git a/crypto/dso/dso_dl.c b/crypto/dso/dso_dl.c index 2b95f92eca..5315e99be7 100644 --- a/crypto/dso/dso_dl.c +++ b/crypto/dso/dso_dl.c @@ -238,7 +238,7 @@ static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2) */ if (!filespec2 || filespec1[0] == '/') { merged = OPENSSL_malloc(strlen(filespec1) + 1); - if (!merged) { + if (merged == NULL) { DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } @@ -249,7 +249,7 @@ static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2) */ else if (!filespec1) { merged = OPENSSL_malloc(strlen(filespec2) + 1); - if (!merged) { + if (merged == NULL) { DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } @@ -273,7 +273,7 @@ static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2) len--; } merged = OPENSSL_malloc(len + 2); - if (!merged) { + if (merged == NULL) { DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } diff --git a/crypto/dso/dso_dlfcn.c b/crypto/dso/dso_dlfcn.c index 1738f3cd71..c06063bbc5 100644 --- a/crypto/dso/dso_dlfcn.c +++ b/crypto/dso/dso_dlfcn.c @@ -282,7 +282,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1, */ if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) { merged = OPENSSL_malloc(strlen(filespec1) + 1); - if (!merged) { + if (merged == NULL) { DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } @@ -293,7 +293,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1, */ else if (!filespec1) { merged = OPENSSL_malloc(strlen(filespec2) + 1); - if (!merged) { + if (merged == NULL) { DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } @@ -316,7 +316,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1, len--; } merged = OPENSSL_malloc(len + 2); - if (!merged) { + if (merged == NULL) { DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } diff --git a/crypto/dso/dso_vms.c b/crypto/dso/dso_vms.c index ffdc57f824..0e1f02e25d 100644 --- a/crypto/dso/dso_vms.c +++ b/crypto/dso/dso_vms.c @@ -512,7 +512,7 @@ static char *vms_merger(DSO *dso, const char *filespec1, } merged = OPENSSL_malloc(nam.NAMX_ESL + 1); - if (!merged) + if (merged == NULL) goto malloc_err; strncpy(merged, nam.NAMX_ESA, nam.NAMX_ESL); merged[nam.NAMX_ESL] = '\0'; @@ -525,7 +525,7 @@ static char *vms_name_converter(DSO *dso, const char *filename) { int len = strlen(filename); char *not_translated = OPENSSL_malloc(len + 1); - if (not_translated) + if (not_translated != NULL) strcpy(not_translated, filename); return (not_translated); } diff --git a/crypto/dso/dso_win32.c b/crypto/dso/dso_win32.c index 8d2123ed08..8bcabff912 100644 --- a/crypto/dso/dso_win32.c +++ b/crypto/dso/dso_win32.c @@ -433,7 +433,7 @@ static char *win32_joiner(DSO *dso, const struct file_st *file_split) } result = OPENSSL_malloc(len + 1); - if (!result) { + if (result == NULL) { DSOerr(DSO_F_WIN32_JOINER, ERR_R_MALLOC_FAILURE); return (NULL); } @@ -499,14 +499,14 @@ static char *win32_merger(DSO *dso, const char *filespec1, } if (!filespec2) { merged = OPENSSL_malloc(strlen(filespec1) + 1); - if (!merged) { + if (merged == NULL) { DSOerr(DSO_F_WIN32_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } strcpy(merged, filespec1); } else if (!filespec1) { merged = OPENSSL_malloc(strlen(filespec2) + 1); - if (!merged) { + if (merged == NULL) { DSOerr(DSO_F_WIN32_MERGER, ERR_R_MALLOC_FAILURE); return (NULL); } diff --git a/crypto/ec/ec2_smpl.c b/crypto/ec/ec2_smpl.c index d6a41a46bf..66bff0dadc 100644 --- a/crypto/ec/ec2_smpl.c +++ b/crypto/ec/ec2_smpl.c @@ -134,7 +134,7 @@ int ec_GF2m_simple_group_init(EC_GROUP *group) group->a = BN_new(); group->b = BN_new(); - if (!group->field || !group->a || !group->b) { + if (group->field == NULL || group->a == NULL || group->b == NULL) { BN_free(group->field); BN_free(group->a); BN_free(group->b); @@ -326,7 +326,7 @@ int ec_GF2m_simple_point_init(EC_POINT *point) point->Y = BN_new(); point->Z = BN_new(); - if (!point->X || !point->Y || !point->Z) { + if (point->X == NULL || point->Y == NULL || point->Z == NULL) { BN_free(point->X); BN_free(point->Y); BN_free(point->Z); diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c index e2f32872c6..19932d541c 100644 --- a/crypto/ec/ec_ameth.c +++ b/crypto/ec/ec_ameth.c @@ -90,7 +90,7 @@ static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key) ASN1_STRING *pstr = NULL; pstr = ASN1_STRING_new(); - if (!pstr) + if (pstr == NULL) return 0; pstr->length = i2d_ECParameters(ec_key, &pstr->data); if (pstr->length <= 0) { @@ -120,7 +120,7 @@ static int eckey_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) if (penclen <= 0) goto err; penc = OPENSSL_malloc(penclen); - if (!penc) + if (penc == NULL) goto err; p = penc; penclen = i2o_ECPublicKey(ec_key, &p); @@ -326,7 +326,7 @@ static int eckey_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) return 0; } ep = OPENSSL_malloc(eplen); - if (!ep) { + if (ep == NULL) { EC_KEY_set_enc_flags(ec_key, old_flags); ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); return 0; @@ -359,7 +359,7 @@ static int ec_bits(const EVP_PKEY *pkey) const EC_GROUP *group; int ret; - if (!order) { + if (order == NULL) { ERR_clear_error(); return 0; } @@ -679,7 +679,7 @@ static int ecdh_cms_set_peerkey(EVP_PKEY_CTX *pctx, goto err; grp = EC_KEY_get0_group(pk->pkey.ec); ecpeer = EC_KEY_new(); - if (!ecpeer) + if (ecpeer == NULL) goto err; if (!EC_KEY_set_group(ecpeer, grp)) goto err; @@ -696,7 +696,7 @@ static int ecdh_cms_set_peerkey(EVP_PKEY_CTX *pctx, if (!o2i_ECPublicKey(&ecpeer, &p, plen)) goto err; pkpeer = EVP_PKEY_new(); - if (!pkpeer) + if (pkpeer == NULL) goto err; EVP_PKEY_set1_EC_KEY(pkpeer, ecpeer); if (EVP_PKEY_derive_set_peer(pctx, pkpeer) > 0) @@ -864,7 +864,7 @@ static int ecdh_cms_encrypt(CMS_RecipientInfo *ri) if (penclen <= 0) goto err; penc = OPENSSL_malloc(penclen); - if (!penc) + if (penc == NULL) goto err; p = penc; penclen = i2o_ECPublicKey(eckey, &p); @@ -922,11 +922,11 @@ static int ecdh_cms_encrypt(CMS_RecipientInfo *ri) /* Package wrap algorithm in an AlgorithmIdentifier */ wrap_alg = X509_ALGOR_new(); - if (!wrap_alg) + if (wrap_alg == NULL) goto err; wrap_alg->algorithm = OBJ_nid2obj(wrap_nid); wrap_alg->parameter = ASN1_TYPE_new(); - if (!wrap_alg->parameter) + if (wrap_alg->parameter == NULL) goto err; if (EVP_CIPHER_param_to_asn1(ctx, wrap_alg->parameter) <= 0) goto err; @@ -955,7 +955,7 @@ static int ecdh_cms_encrypt(CMS_RecipientInfo *ri) if (!penc || !penclen) goto err; wrap_str = ASN1_STRING_new(); - if (!wrap_str) + if (wrap_str == NULL) goto err; ASN1_STRING_set0(wrap_str, penc, penclen); penc = NULL; diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c index bd6592b647..dacbdbf6ff 100644 --- a/crypto/ec/ec_asn1.c +++ b/crypto/ec/ec_asn1.c @@ -383,7 +383,7 @@ static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field) goto err; char_two->p.tpBasis = ASN1_INTEGER_new(); - if (!char_two->p.tpBasis) { + if (char_two->p.tpBasis == NULL) { ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); goto err; } @@ -398,7 +398,7 @@ static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field) goto err; char_two->p.ppBasis = X9_62_PENTANOMIAL_new(); - if (!char_two->p.ppBasis) { + if (char_two->p.ppBasis == NULL) { ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); goto err; } @@ -411,7 +411,7 @@ static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field) /* for ONB the parameters are (asn1) NULL */ char_two->p.onBasis = ASN1_NULL_new(); - if (!char_two->p.onBasis) { + if (char_two->p.onBasis == NULL) { ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); goto err; } @@ -1028,6 +1028,10 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len) if (priv_key->privateKey) { if (ret->priv_key == NULL) ret->priv_key = BN_secure_new(); + if (ret->priv_key == NULL) { + ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); + goto err; + } ret->priv_key = BN_bin2bn(ASN1_STRING_data(priv_key->privateKey), ASN1_STRING_length(priv_key->privateKey), ret->priv_key); diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c index ddb3257d77..d5706010ff 100644 --- a/crypto/ec/ec_key.c +++ b/crypto/ec/ec_key.c @@ -352,12 +352,12 @@ int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, return 0; } ctx = BN_CTX_new(); - if (!ctx) + if (ctx == NULL) goto err; point = EC_POINT_new(key->group); - if (!point) + if (point == NULL) goto err; tx = BN_CTX_get(ctx); diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c index 793645de8a..7cb4759f65 100644 --- a/crypto/ec/ec_lib.c +++ b/crypto/ec/ec_lib.c @@ -91,10 +91,10 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth) ret->meth = meth; ret->order = BN_new(); - if (!ret->order) + if (ret->order == NULL) goto err; ret->cofactor = BN_new(); - if (!ret->cofactor) + if (ret->cofactor == NULL) goto err; ret->asn1_flag = OPENSSL_EC_NAMED_CURVE; ret->asn1_form = POINT_CONVERSION_UNCOMPRESSED; @@ -464,9 +464,9 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) EC_GROUP_get_curve_name(a) != EC_GROUP_get_curve_name(b)) return 1; - if (!ctx) + if (ctx == NULL) ctx_new = ctx = BN_CTX_new(); - if (!ctx) + if (ctx == NULL) return -1; BN_CTX_start(ctx); @@ -476,7 +476,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) b1 = BN_CTX_get(ctx); b2 = BN_CTX_get(ctx); b3 = BN_CTX_get(ctx); - if (!b3) { + if (b3 == NULL) { BN_CTX_end(ctx); BN_CTX_free(ctx_new); return -1; @@ -1075,7 +1075,7 @@ int ec_precompute_mont_data(EC_GROUP *group) goto err; group->mont_data = BN_MONT_CTX_new(); - if (!group->mont_data) + if (group->mont_data == NULL) goto err; if (!BN_MONT_CTX_set(group->mont_data, group->order, ctx)) { diff --git a/crypto/ec/ec_mult.c b/crypto/ec/ec_mult.c index a3d9885dcf..7e29397cba 100644 --- a/crypto/ec/ec_mult.c +++ b/crypto/ec/ec_mult.c @@ -101,7 +101,7 @@ static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP *group) return NULL; ret = OPENSSL_zalloc(sizeof(*ret)); - if (!ret) { + if (ret == NULL) { ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); return ret; } @@ -296,10 +296,10 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]); /* Ensure wNAF is initialised in case we end up going to err */ - if (wNAF) + if (wNAF != NULL) wNAF[0] = NULL; /* preliminary pivot */ - if (!wsize || !wNAF_len || !wNAF || !val_sub) { + if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } @@ -657,7 +657,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) * and store */ points = OPENSSL_malloc(sizeof(*points) * (num + 1)); - if (!points) { + if (points == 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 aa1fa9f53f..ecae0bfe26 100644 --- a/crypto/ec/ec_pmeth.c +++ b/crypto/ec/ec_pmeth.c @@ -93,7 +93,7 @@ static int pkey_ec_init(EVP_PKEY_CTX *ctx) EC_PKEY_CTX *dctx; dctx = OPENSSL_zalloc(sizeof(*dctx)); - if (!dctx) + if (dctx == NULL) return 0; dctx->cofactor_mode = -1; @@ -248,7 +248,7 @@ static int pkey_ec_kdf_derive(EVP_PKEY_CTX *ctx, if (!pkey_ec_derive(ctx, NULL, &ktmplen)) return 0; ktmp = OPENSSL_malloc(ktmplen); - if (!ktmp) + if (ktmp == NULL) return 0; if (!pkey_ec_derive(ctx, ktmp, &ktmplen)) goto err; @@ -442,7 +442,7 @@ static int pkey_ec_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return 0; } ec = EC_KEY_new(); - if (!ec) + if (ec == NULL) return 0; ret = EC_KEY_set_group(ec, dctx->gen_group); if (ret) diff --git a/crypto/ec/eck_prn.c b/crypto/ec/eck_prn.c index f1248b8da9..b9653ac9f9 100644 --- a/crypto/ec/eck_prn.c +++ b/crypto/ec/eck_prn.c @@ -119,7 +119,7 @@ int EC_KEY_print(BIO *bp, const EC_KEY *x, int off) EVP_PKEY *pk; int ret; pk = EVP_PKEY_new(); - if (!pk || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *)x)) + if (pk == NULL || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *)x)) return 0; ret = EVP_PKEY_print_private(bp, pk, off, NULL); EVP_PKEY_free(pk); @@ -131,7 +131,7 @@ int ECParameters_print(BIO *bp, const EC_KEY *x) EVP_PKEY *pk; int ret; pk = EVP_PKEY_new(); - if (!pk || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *)x)) + if (pk == NULL || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *)x)) return 0; ret = EVP_PKEY_print_params(bp, pk, 4, NULL); EVP_PKEY_free(pk); diff --git a/crypto/ec/ecp_nistp256.c b/crypto/ec/ecp_nistp256.c index 110984b125..48ed2c452e 100644 --- a/crypto/ec/ecp_nistp256.c +++ b/crypto/ec/ecp_nistp256.c @@ -1817,7 +1817,7 @@ static NISTP256_PRE_COMP *nistp256_pre_comp_new() { NISTP256_PRE_COMP *ret = NULL; ret = OPENSSL_malloc(sizeof(*ret)); - if (!ret) { + if (ret == NULL) { ECerr(EC_F_NISTP256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); return ret; } diff --git a/crypto/ec/ecp_nistp521.c b/crypto/ec/ecp_nistp521.c index febf5e94b7..dd5b19b581 100644 --- a/crypto/ec/ecp_nistp521.c +++ b/crypto/ec/ecp_nistp521.c @@ -1646,7 +1646,7 @@ static NISTP521_PRE_COMP *nistp521_pre_comp_new() { NISTP521_PRE_COMP *ret = OPENSSL_zalloc(sizeof(*ret)); - if (!ret) { + if (ret == NULL) { ECerr(EC_F_NISTP521_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); return ret; } diff --git a/crypto/ec/ecp_nistz256.c b/crypto/ec/ecp_nistz256.c index 503606085f..3d83303349 100644 --- a/crypto/ec/ecp_nistz256.c +++ b/crypto/ec/ecp_nistz256.c @@ -1102,10 +1102,10 @@ __owur static int ecp_nistz256_set_from_affine(EC_POINT *out, const EC_GROUP *gr int ret = 0; x = BN_new(); - if (!x) + if (x == NULL) return 0; y = BN_new(); - if (!y) { + if (y == NULL) { BN_free(x); return 0; } @@ -1305,13 +1305,13 @@ __owur static int ecp_nistz256_points_mul(const EC_GROUP *group, * handled like a normal point. */ new_scalars = OPENSSL_malloc((num + 1) * sizeof(BIGNUM *)); - if (!new_scalars) { + if (new_scalars == NULL) { ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE); goto err; } new_points = OPENSSL_malloc((num + 1) * sizeof(EC_POINT *)); - if (!new_points) { + if (new_points == NULL) { ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE); goto err; } @@ -1410,7 +1410,7 @@ static EC_PRE_COMP *ecp_nistz256_pre_comp_new(const EC_GROUP *group) ret = OPENSSL_malloc(sizeof(*ret)); - if (!ret) { + if (ret == NULL) { ECerr(EC_F_ECP_NISTZ256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); return ret; } diff --git a/crypto/ec/ecp_smpl.c b/crypto/ec/ecp_smpl.c index df7314a73a..a4830cb006 100644 --- a/crypto/ec/ecp_smpl.c +++ b/crypto/ec/ecp_smpl.c @@ -132,7 +132,7 @@ int ec_GFp_simple_group_init(EC_GROUP *group) group->field = BN_new(); group->a = BN_new(); group->b = BN_new(); - if (!group->field || !group->a || !group->b) { + if (group->field == NULL || group->a == NULL || group->b == NULL) { BN_free(group->field); BN_free(group->a); BN_free(group->b); @@ -359,7 +359,7 @@ int ec_GFp_simple_point_init(EC_POINT *point) point->Z = BN_new(); point->Z_is_one = 0; - if (!point->X || !point->Y || !point->Z) { + if (point->X == NULL || point->Y == NULL || point->Z == NULL) { BN_free(point->X); BN_free(point->Y); BN_free(point->Z); diff --git a/crypto/ecdsa/ecs_ossl.c b/crypto/ecdsa/ecs_ossl.c index 27266e9173..bff80f9e11 100644 --- a/crypto/ecdsa/ecs_ossl.c +++ b/crypto/ecdsa/ecs_ossl.c @@ -120,7 +120,7 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, r = BN_new(); /* this value is later returned in *rp */ order = BN_new(); X = BN_new(); - if (!k || !r || !order || !X) { + if (k == NULL || r == NULL || order == NULL || X == NULL) { ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE); goto err; } @@ -265,7 +265,7 @@ static ECDSA_SIG *ecdsa_do_sign(const unsigned char *dgst, int dgst_len, } ret = ECDSA_SIG_new(); - if (!ret) { + if (ret == NULL) { ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); return NULL; } @@ -371,7 +371,7 @@ static int ecdsa_do_verify(const unsigned char *dgst, int dgst_len, } ctx = BN_CTX_new(); - if (!ctx) { + if (ctx == NULL) { ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); return -1; } diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c index d058dba0a8..d1c0029d35 100644 --- a/crypto/engine/eng_cryptodev.c +++ b/crypto/engine/eng_cryptodev.c @@ -1233,6 +1233,8 @@ cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, int ret = 0; t2 = BN_new(); + if (t2 == NULL) + goto err; /* v = ( g^u1 * y^u2 mod p ) mod q */ /* let t1 = g ^ u1 mod p */ @@ -1289,6 +1291,8 @@ static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r, BN_num_bytes(dsa->q), s) == 0) { dsaret = DSA_SIG_new(); + if (dsaret == NULL) + goto err; dsaret->r = r; dsaret->s = s; } else { diff --git a/crypto/engine/eng_dyn.c b/crypto/engine/eng_dyn.c index 100b050b9d..aed50f6474 100644 --- a/crypto/engine/eng_dyn.c +++ b/crypto/engine/eng_dyn.c @@ -204,12 +204,12 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) { dynamic_data_ctx *c = OPENSSL_zalloc(sizeof(*c)); - if (!c) { + if (c == NULL) { ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE); return 0; } c->dirs = sk_OPENSSL_STRING_new_null(); - if (!c->dirs) { + if (c->dirs == NULL) { ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE); OPENSSL_free(c); return 0; @@ -278,7 +278,7 @@ static dynamic_data_ctx *dynamic_get_data_ctx(ENGINE *e) static ENGINE *engine_dynamic(void) { ENGINE *ret = ENGINE_new(); - if (!ret) + if (ret == NULL) return NULL; if (!ENGINE_set_id(ret, engine_dynamic_id) || !ENGINE_set_name(ret, engine_dynamic_name) || @@ -438,8 +438,10 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) ENGINE cpy; dynamic_fns fns; - if (!ctx->dynamic_dso) + if (ctx->dynamic_dso == NULL) ctx->dynamic_dso = DSO_new(); + if (ctx->dynamic_dso == NULL) + return 0; if (!ctx->DYNAMIC_LIBNAME) { if (!ctx->engine_id) return 0; diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c index a113ebc57c..9ebb6943be 100644 --- a/crypto/engine/eng_lib.c +++ b/crypto/engine/eng_lib.c @@ -163,7 +163,7 @@ static int int_cleanup_check(int create) static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb) { ENGINE_CLEANUP_ITEM *item = OPENSSL_malloc(sizeof(*item)); - if (!item) + if (item == NULL) return NULL; item->cb = cb; return item; diff --git a/crypto/engine/eng_list.c b/crypto/engine/eng_list.c index 54141f3ea6..cfd4f7e25c 100644 --- a/crypto/engine/eng_list.c +++ b/crypto/engine/eng_list.c @@ -332,7 +332,7 @@ ENGINE *ENGINE_by_id(const char *id) iterator = engine_list_head; while (iterator && (strcmp(id, iterator->id) != 0)) iterator = iterator->next; - if (iterator) { + if (iterator != NULL) { /* * We need to return a structural reference. If this is an ENGINE * type that returns copies, make a duplicate - otherwise increment @@ -340,7 +340,7 @@ ENGINE *ENGINE_by_id(const char *id) */ if (iterator->flags & ENGINE_FLAGS_BY_ID_COPY) { ENGINE *cp = ENGINE_new(); - if (!cp) + if (cp == NULL) iterator = NULL; else { engine_cpy(cp, iterator); @@ -352,7 +352,7 @@ ENGINE *ENGINE_by_id(const char *id) } } CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); - if (iterator) + if (iterator != NULL) return iterator; /* * Prevent infinite recusrion if we're looking for the dynamic engine. diff --git a/crypto/engine/eng_openssl.c b/crypto/engine/eng_openssl.c index 244a6096c6..41754f7627 100644 --- a/crypto/engine/eng_openssl.c +++ b/crypto/engine/eng_openssl.c @@ -186,7 +186,7 @@ static int bind_helper(ENGINE *e) static ENGINE *engine_openssl(void) { ENGINE *ret = ENGINE_new(); - if (!ret) + if (ret == NULL) return NULL; if (!bind_helper(ret)) { ENGINE_free(ret); @@ -429,7 +429,7 @@ static int ossl_hmac_init(EVP_PKEY_CTX *ctx) OSSL_HMAC_PKEY_CTX *hctx; hctx = OPENSSL_zalloc(sizeof(*hctx)); - if (!hctx) + if (hctx == NULL) return 0; hctx->ktmp.type = V_ASN1_OCTET_STRING; HMAC_CTX_init(&hctx->ctx); @@ -579,7 +579,7 @@ static int ossl_register_hmac_meth(void) { EVP_PKEY_METHOD *meth; meth = EVP_PKEY_meth_new(EVP_PKEY_HMAC, 0); - if (!meth) + if (meth == NULL) return 0; EVP_PKEY_meth_set_init(meth, ossl_hmac_init); EVP_PKEY_meth_set_copy(meth, ossl_hmac_copy); diff --git a/crypto/engine/eng_rdrand.c b/crypto/engine/eng_rdrand.c index 9316d6fe21..48726e2543 100644 --- a/crypto/engine/eng_rdrand.c +++ b/crypto/engine/eng_rdrand.c @@ -120,7 +120,7 @@ static int bind_helper(ENGINE *e) static ENGINE *ENGINE_rdrand(void) { ENGINE *ret = ENGINE_new(); - if (!ret) + if (ret == NULL) return NULL; if (!bind_helper(ret)) { ENGINE_free(ret); diff --git a/crypto/engine/eng_table.c b/crypto/engine/eng_table.c index 26b92308af..5fd00ddc2c 100644 --- a/crypto/engine/eng_table.c +++ b/crypto/engine/eng_table.c @@ -148,7 +148,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup, fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate); if (!fnd) { fnd = OPENSSL_malloc(sizeof(*fnd)); - if (!fnd) + if (fnd == NULL) goto end; fnd->uptodate = 1; fnd->nid = *nids; diff --git a/crypto/err/err.c b/crypto/err/err.c index 1b94ce5a02..077929c295 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -279,7 +279,7 @@ static LHASH_OF(ERR_STRING_DATA) *get_hash(int create, int lockit) int_error_hash = lh_ERR_STRING_DATA_new(); CRYPTO_pop_info(); } - if (int_error_hash) + if (int_error_hash != NULL) ret = int_error_hash; if (lockit) CRYPTO_w_unlock(CRYPTO_LOCK_ERR); @@ -326,7 +326,7 @@ static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit) int_thread_hash = lh_ERR_STATE_new(); CRYPTO_pop_info(); } - if (int_thread_hash) { + if (int_thread_hash != NULL) { int_thread_hash_references++; ret = int_thread_hash; } diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 1d25d97c53..607f0a1a0d 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -126,7 +126,7 @@ EVP_MD_CTX *EVP_MD_CTX_create(void) { EVP_MD_CTX *ctx = OPENSSL_malloc(sizeof(*ctx)); - if (ctx) + if (ctx != NULL) EVP_MD_CTX_init(ctx); return ctx; @@ -288,7 +288,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) out->md_data = tmp_buf; else { out->md_data = OPENSSL_malloc(out->digest->ctx_size); - if (!out->md_data) { + if (out->md_data == NULL) { EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c index b02cf6eef2..efa724a363 100644 --- a/crypto/evp/e_aes.c +++ b/crypto/evp/e_aes.c @@ -1265,7 +1265,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) if (gctx->iv != c->iv) OPENSSL_free(gctx->iv); gctx->iv = OPENSSL_malloc(arg); - if (!gctx->iv) + if (gctx->iv == NULL) return 0; } gctx->ivlen = arg; @@ -1359,7 +1359,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) gctx_out->iv = out->iv; else { gctx_out->iv = OPENSSL_malloc(gctx->ivlen); - if (!gctx_out->iv) + if (gctx_out->iv == NULL) return 0; memcpy(gctx_out->iv, gctx->iv, gctx->ivlen); } diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 7f55c4196b..7ef0dd81d9 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -74,7 +74,7 @@ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) { EVP_CIPHER_CTX *ctx = OPENSSL_malloc(sizeof(*ctx)); - if (ctx) + if (ctx != NULL) EVP_CIPHER_CTX_init(ctx); return ctx; } @@ -159,7 +159,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ctx->cipher = cipher; if (ctx->cipher->ctx_size) { ctx->cipher_data = OPENSSL_zalloc(ctx->cipher->ctx_size); - if (!ctx->cipher_data) { + if (ctx->cipher_data == NULL) { EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE); return 0; } @@ -620,7 +620,7 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) if (in->cipher_data && in->cipher->ctx_size) { out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size); - if (!out->cipher_data) { + if (out->cipher_data == NULL) { EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/evp/evp_key.c b/crypto/evp/evp_key.c index 5c03a91a94..3e2c989954 100644 --- a/crypto/evp/evp_key.c +++ b/crypto/evp/evp_key.c @@ -104,6 +104,8 @@ int EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt, if ((prompt == NULL) && (prompt_string[0] != '\0')) prompt = prompt_string; ui = UI_new(); + if (ui == NULL) + return -1; UI_add_input_string(ui, prompt, 0, buf, min, (len >= BUFSIZ) ? BUFSIZ - 1 : len); if (verify) diff --git a/crypto/evp/p_sign.c b/crypto/evp/p_sign.c index 90a5fc6a42..df507a5178 100644 --- a/crypto/evp/p_sign.c +++ b/crypto/evp/p_sign.c @@ -90,7 +90,7 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t sltmp = (size_t)EVP_PKEY_size(pkey); i = 0; pkctx = EVP_PKEY_CTX_new(pkey, NULL); - if (!pkctx) + if (pkctx == NULL) goto err; if (EVP_PKEY_sign_init(pkctx) <= 0) goto err; diff --git a/crypto/evp/p_verify.c b/crypto/evp/p_verify.c index 098bf9149c..892c646b36 100644 --- a/crypto/evp/p_verify.c +++ b/crypto/evp/p_verify.c @@ -88,7 +88,7 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { i = -1; pkctx = EVP_PKEY_CTX_new(pkey, NULL); - if (!pkctx) + if (pkctx == NULL) goto err; if (EVP_PKEY_verify_init(pkctx) <= 0) goto err; diff --git a/crypto/evp/pmeth_gn.c b/crypto/evp/pmeth_gn.c index 9416e1ab72..368c687e2f 100644 --- a/crypto/evp/pmeth_gn.c +++ b/crypto/evp/pmeth_gn.c @@ -146,11 +146,13 @@ int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) return -1; } - if (!ppkey) + if (ppkey == NULL) return -1; - if (!*ppkey) + if (*ppkey == NULL) *ppkey = EVP_PKEY_new(); + if (*ppkey == NULL) + return -1; ret = ctx->pmeth->keygen(ctx, *ppkey); if (ret <= 0) { diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 67ba16d85e..bbc4565816 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -160,7 +160,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) } ret = OPENSSL_zalloc(sizeof(*ret)); - if (!ret) { + if (ret == NULL) { #ifndef OPENSSL_NO_ENGINE if (e) ENGINE_finish(e); @@ -190,7 +190,7 @@ EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags) EVP_PKEY_METHOD *pmeth; pmeth = OPENSSL_zalloc(sizeof(*pmeth)); - if (!pmeth) + if (pmeth == NULL) return NULL; pmeth->pkey_id = id; @@ -277,7 +277,7 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx) } #endif rctx = OPENSSL_malloc(sizeof(*rctx)); - if (!rctx) + if (rctx == NULL) return NULL; rctx->pmeth = pctx->pmeth; @@ -311,7 +311,7 @@ int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth) { if (app_pkey_methods == NULL) { app_pkey_methods = sk_EVP_PKEY_METHOD_new(pmeth_cmp); - if (!app_pkey_methods) + if (app_pkey_methods == NULL) return 0; } if (!sk_EVP_PKEY_METHOD_push(app_pkey_methods, pmeth)) diff --git a/crypto/evp/scrypt.c b/crypto/evp/scrypt.c index 380e1fa792..26b4e596ba 100644 --- a/crypto/evp/scrypt.c +++ b/crypto/evp/scrypt.c @@ -268,7 +268,7 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen, return 1; B = OPENSSL_malloc(Blen + Vlen); - if (B == 0) + if (B == NULL) return 0; X = (uint32_t *)(B + Blen); T = X + 32 * r; diff --git a/crypto/ex_data.c b/crypto/ex_data.c index 62d03bb98d..29d8071eef 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c @@ -198,7 +198,7 @@ int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, if (!ip) return -1; a = (CRYPTO_EX_DATA_FUNCS *)OPENSSL_malloc(sizeof(*a)); - if (!a) { + if (a == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX, ERR_R_MALLOC_FAILURE); goto err; } @@ -247,7 +247,7 @@ int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) storage = stack; else storage = OPENSSL_malloc(sizeof(*storage) * mx); - if (storage) + if (storage != NULL) for (i = 0; i < mx; i++) storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(ip->meth, i); } @@ -297,7 +297,7 @@ int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, storage = stack; else storage = OPENSSL_malloc(sizeof(*storage) * mx); - if (storage) + if (storage != NULL) for (i = 0; i < mx; i++) storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(ip->meth, i); } @@ -342,7 +342,7 @@ void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) storage = stack; else storage = OPENSSL_malloc(sizeof(*storage) * mx); - if (storage) + if (storage != NULL) for (i = 0; i < mx; i++) storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(ip->meth, i); } diff --git a/crypto/hmac/hm_ameth.c b/crypto/hmac/hm_ameth.c index 20abe4f087..df6bf0b3ef 100644 --- a/crypto/hmac/hm_ameth.c +++ b/crypto/hmac/hm_ameth.c @@ -107,7 +107,7 @@ static int old_hmac_decode(EVP_PKEY *pkey, { ASN1_OCTET_STRING *os; os = ASN1_OCTET_STRING_new(); - if (!os || !ASN1_OCTET_STRING_set(os, *pder, derlen)) + if (os == NULL || !ASN1_OCTET_STRING_set(os, *pder, derlen)) goto err; if (!EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os)) goto err; diff --git a/crypto/hmac/hm_pmeth.c b/crypto/hmac/hm_pmeth.c index ff9dbe35b0..e06a1db0ea 100644 --- a/crypto/hmac/hm_pmeth.c +++ b/crypto/hmac/hm_pmeth.c @@ -77,7 +77,7 @@ static int pkey_hmac_init(EVP_PKEY_CTX *ctx) HMAC_PKEY_CTX *hctx; hctx = OPENSSL_zalloc(sizeof(*hctx)); - if (!hctx) + if (hctx == NULL) return 0; hctx->ktmp.type = V_ASN1_OCTET_STRING; HMAC_CTX_init(&hctx->ctx); diff --git a/crypto/jpake/jpake.c b/crypto/jpake/jpake.c index a8aa87d197..abbcb89a2a 100644 --- a/crypto/jpake/jpake.c +++ b/crypto/jpake/jpake.c @@ -201,6 +201,9 @@ static int generate_zkp(JPAKE_STEP_PART *p, const BIGNUM *x, BIGNUM *h = BN_new(); BIGNUM *t = BN_new(); + if (r == NULL || h == NULL || t == NULL) + goto end; + /*- * r in [0,q) * XXX: Java chooses r in [0, 2^160) - i.e. distribution not uniform @@ -235,6 +238,9 @@ static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg, BIGNUM *t3 = BN_new(); int ret = 0; + if (h == NULL || t1 == NULL || t2 == NULL || t3 == NULL) + goto end; + if (!zkp_hash(h, zkpg, p, ctx->p.peer_name)) goto end; diff --git a/crypto/lhash/lh_test.c b/crypto/lhash/lh_test.c index d9db83f7ae..52010d9131 100644 --- a/crypto/lhash/lh_test.c +++ b/crypto/lhash/lh_test.c @@ -77,6 +77,8 @@ main() break; i = strlen(buf); p = OPENSSL_malloc(i + 1); + if (p == NULL) + abort(); memcpy(p, buf, i + 1); lh_insert(conf, p); } diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c index 2cd1169918..c19847eb28 100644 --- a/crypto/mem_dbg.c +++ b/crypto/mem_dbg.c @@ -792,7 +792,7 @@ void CRYPTO_mem_leaks_fp(FILE *fp) MemCheck_off(); b = BIO_new(BIO_s_file()); MemCheck_on(); - if (!b) + if (b == NULL) return; BIO_set_fp(b, fp, BIO_NOCLOSE); CRYPTO_mem_leaks(b); diff --git a/crypto/modes/gcm128.c b/crypto/modes/gcm128.c index f28e07ceb0..0615224dd0 100644 --- a/crypto/modes/gcm128.c +++ b/crypto/modes/gcm128.c @@ -1701,7 +1701,7 @@ GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block) { GCM128_CONTEXT *ret; - if ((ret = OPENSSL_malloc(sizeof(*ret)))) + if ((ret = OPENSSL_malloc(sizeof(*ret))) != NULL) CRYPTO_gcm128_init(ret, key, block); return ret; diff --git a/crypto/modes/ocb128.c b/crypto/modes/ocb128.c index ed484606e5..2685652d3f 100644 --- a/crypto/modes/ocb128.c +++ b/crypto/modes/ocb128.c @@ -210,7 +210,7 @@ OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec, OCB128_CONTEXT *octx; int ret; - if ((octx = OPENSSL_malloc(sizeof(*octx)))) { + if ((octx = OPENSSL_malloc(sizeof(*octx))) != NULL) { ret = CRYPTO_ocb128_init(octx, keyenc, keydec, encrypt, decrypt); if (ret) return octx; @@ -230,7 +230,7 @@ int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec, ctx->l_index = 0; ctx->max_l_index = 1; ctx->l = OPENSSL_malloc(ctx->max_l_index * 16); - if (!ctx->l) + if (ctx->l == NULL) return 0; /* @@ -268,7 +268,7 @@ int CRYPTO_ocb128_copy_ctx(OCB128_CONTEXT *dest, OCB128_CONTEXT *src, dest->keydec = keydec; if (src->l) { dest->l = OPENSSL_malloc(src->max_l_index * 16); - if (!dest->l) + if (dest->l == NULL) return 0; memcpy(dest->l, src->l, (src->l_index + 1) * 16); } diff --git a/crypto/objects/o_names.c b/crypto/objects/o_names.c index 7a24ad01f2..d7441cad82 100644 --- a/crypto/objects/o_names.c +++ b/crypto/objects/o_names.c @@ -85,7 +85,7 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), MemCheck_off(); name_funcs = OPENSSL_zalloc(sizeof(*name_funcs)); MemCheck_on(); - if (!name_funcs) { + if (name_funcs == NULL) { OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); return (0); } @@ -308,7 +308,7 @@ void OBJ_NAME_do_all_sorted(int type, d.names = OPENSSL_malloc(sizeof(*d.names) * lh_OBJ_NAME_num_items(names_lh)); /* Really should return an error if !d.names...but its a void function! */ - if (d.names) { + if (d.names != NULL) { d.n = 0; OBJ_NAME_do_all(type, do_all_sorted_fn, &d); diff --git a/crypto/objects/obj_xref.c b/crypto/objects/obj_xref.c index da3469f0e8..6e35f5746f 100644 --- a/crypto/objects/obj_xref.c +++ b/crypto/objects/obj_xref.c @@ -147,16 +147,16 @@ int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid) int OBJ_add_sigid(int signid, int dig_id, int pkey_id) { nid_triple *ntr; - if (!sig_app) + if (sig_app == NULL) sig_app = sk_nid_triple_new(sig_sk_cmp); - if (!sig_app) + if (sig_app == NULL) return 0; - if (!sigx_app) + if (sigx_app == NULL) sigx_app = sk_nid_triple_new(sigx_cmp); - if (!sigx_app) + if (sigx_app == NULL) return 0; ntr = OPENSSL_malloc(sizeof(*ntr)); - if (!ntr) + if (ntr == NULL) return 0; ntr->sign_id = signid; ntr->hash_id = dig_id; diff --git a/crypto/ocsp/ocsp_cl.c b/crypto/ocsp/ocsp_cl.c index 2b771460e8..e6e7fc1499 100644 --- a/crypto/ocsp/ocsp_cl.c +++ b/crypto/ocsp/ocsp_cl.c @@ -125,12 +125,12 @@ int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm) int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert) { OCSP_SIGNATURE *sig; - if (!req->optionalSignature) + if (req->optionalSignature == NULL) req->optionalSignature = OCSP_SIGNATURE_new(); sig = req->optionalSignature; - if (!sig) + if (sig == NULL) return 0; - if (!cert) + if (cert == NULL) return 1; if (sig->certs == NULL && (sig->certs = sk_X509_new_null()) == NULL) diff --git a/crypto/ocsp/ocsp_ht.c b/crypto/ocsp/ocsp_ht.c index 2c92ee7554..8f1cb08c33 100644 --- a/crypto/ocsp/ocsp_ht.c +++ b/crypto/ocsp/ocsp_ht.c @@ -115,7 +115,7 @@ OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline) { OCSP_REQ_CTX *rctx = OPENSSL_zalloc(sizeof(*rctx)); - if (!rctx) + if (rctx == NULL) return NULL; rctx->state = OHS_ERROR; rctx->max_resp_len = OCSP_MAX_RESP_LENGTH; @@ -126,7 +126,7 @@ OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline) else rctx->iobuflen = OCSP_MAX_LINE_LEN; rctx->iobuf = OPENSSL_malloc(rctx->iobuflen); - if (!rctx->iobuf || !rctx->mem) { + if (rctx->iobuf == NULL || rctx->mem == NULL) { OCSP_REQ_CTX_free(rctx); return NULL; } @@ -232,7 +232,7 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, OCSP_REQUEST *req, OCSP_REQ_CTX *rctx = NULL; rctx = OCSP_REQ_CTX_new(io, maxline); - if (!rctx) + if (rctx == NULL) return NULL; if (!OCSP_REQ_CTX_http(rctx, "POST", path)) @@ -533,7 +533,7 @@ OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req) ctx = OCSP_sendreq_new(b, path, req, -1); - if (!ctx) + if (ctx == NULL) return NULL; do { diff --git a/crypto/ocsp/ocsp_srv.c b/crypto/ocsp/ocsp_srv.c index 8f196c81ff..a39fa48648 100644 --- a/crypto/ocsp/ocsp_srv.c +++ b/crypto/ocsp/ocsp_srv.c @@ -184,11 +184,13 @@ OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, break; case V_OCSP_CERTSTATUS_GOOD: - cs->value.good = ASN1_NULL_new(); + if ((cs->value.good = ASN1_NULL_new()) == NULL) + goto err; break; case V_OCSP_CERTSTATUS_UNKNOWN: - cs->value.unknown = ASN1_NULL_new(); + if ((cs->value.unknown = ASN1_NULL_new()) == NULL) + goto err; break; default: diff --git a/crypto/ocsp/v3_ocsp.c b/crypto/ocsp/v3_ocsp.c index ab8c4376b1..9a49422df7 100644 --- a/crypto/ocsp/v3_ocsp.c +++ b/crypto/ocsp/v3_ocsp.c @@ -234,10 +234,13 @@ static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length) { ASN1_OCTET_STRING *os, **pos; pos = a; - if (!pos || !*pos) + if (pos == NULL || *pos == NULL) { os = ASN1_OCTET_STRING_new(); - else + if (os == NULL) + goto err; + } else { os = *pos; + } if (!ASN1_OCTET_STRING_set(os, *pp, length)) goto err; diff --git a/crypto/pem/pem_info.c b/crypto/pem/pem_info.c index 045f568e0c..0cbd081b38 100644 --- a/crypto/pem/pem_info.c +++ b/crypto/pem/pem_info.c @@ -172,6 +172,8 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, xi->enc_len = 0; xi->x_pkey = X509_PKEY_new(); + if (xi->x_pkey == NULL) + goto err; ptype = EVP_PKEY_RSA; pp = &xi->x_pkey->dec_pkey; if ((int)strlen(header) > 10) /* assume encrypted */ @@ -193,6 +195,8 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, xi->enc_len = 0; xi->x_pkey = X509_PKEY_new(); + if (xi->x_pkey == NULL) + goto err; ptype = EVP_PKEY_DSA; pp = &xi->x_pkey->dec_pkey; if ((int)strlen(header) > 10) /* assume encrypted */ @@ -214,6 +218,8 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, xi->enc_len = 0; xi->x_pkey = X509_PKEY_new(); + if (xi->x_pkey == NULL) + goto err; ptype = EVP_PKEY_EC; pp = &xi->x_pkey->dec_pkey; if ((int)strlen(header) > 10) /* assume encrypted */ diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c index 893675fc40..1a249f5588 100644 --- a/crypto/pem/pem_pkey.c +++ b/crypto/pem/pem_pkey.c @@ -173,7 +173,7 @@ EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x) if ((slen = pem_check_suffix(nm, "PARAMETERS")) > 0) { ret = EVP_PKEY_new(); - if (!ret) + if (ret == NULL) goto err; if (!EVP_PKEY_set_type_str(ret, nm, slen) || !ret->ameth->param_decode diff --git a/crypto/pem/pvkfmt.c b/crypto/pem/pvkfmt.c index 47fb9ac71d..50f19f3068 100644 --- a/crypto/pem/pvkfmt.c +++ b/crypto/pem/pvkfmt.c @@ -98,7 +98,7 @@ static int read_lebn(const unsigned char **in, unsigned int nbyte, BIGNUM **r) unsigned int i; p = *in + nbyte - 1; tmpbuf = OPENSSL_malloc(nbyte); - if (!tmpbuf) + if (tmpbuf == NULL) return 0; q = tmpbuf; for (i = 0; i < nbyte; i++) @@ -269,7 +269,7 @@ static EVP_PKEY *do_b2i_bio(BIO *in, int ispub) length = blob_length(bitlen, isdss, ispub); buf = OPENSSL_malloc(length); - if (!buf) { + if (buf == NULL) { PEMerr(PEM_F_DO_B2I_BIO, ERR_R_MALLOC_FAILURE); goto err; } @@ -301,7 +301,7 @@ static EVP_PKEY *b2i_dss(const unsigned char **in, unsigned int length, dsa = DSA_new(); ret = EVP_PKEY_new(); - if (!dsa || !ret) + if (dsa == NULL || ret == NULL) goto memerr; if (!read_lebn(&p, nbyte, &dsa->p)) goto memerr; @@ -350,10 +350,10 @@ static EVP_PKEY *b2i_rsa(const unsigned char **in, unsigned int length, hnbyte = (bitlen + 15) >> 4; rsa = RSA_new(); ret = EVP_PKEY_new(); - if (!rsa || !ret) + if (rsa == NULL || ret == NULL) goto memerr; rsa->e = BN_new(); - if (!rsa->e) + if (rsa->e == NULL) goto memerr; if (!BN_set_word(rsa->e, read_ledword(&p))) goto memerr; @@ -468,7 +468,7 @@ static int do_i2b(unsigned char **out, EVP_PKEY *pk, int ispub) p = *out; else { p = OPENSSL_malloc(outlen); - if (!p) + if (p == NULL) return -1; *out = p; noinc = 1; @@ -687,7 +687,7 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in, goto err; } enctmp = OPENSSL_malloc(keylen + 8); - if (!enctmp) { + if (enctmp == NULL) { PEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE); goto err; } @@ -755,7 +755,7 @@ EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u) return 0; buflen = (int)keylen + saltlen; buf = OPENSSL_malloc(buflen); - if (!buf) { + if (buf == NULL) { PEMerr(PEM_F_B2I_PVK_BIO, ERR_R_MALLOC_FAILURE); return 0; } @@ -790,7 +790,7 @@ static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel, p = *out; else { p = OPENSSL_malloc(outlen); - if (!p) { + if (p == NULL) { PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE); return -1; } diff --git a/crypto/pkcs12/p12_key.c b/crypto/pkcs12/p12_key.c index 879f157be0..fe378d765f 100644 --- a/crypto/pkcs12/p12_key.c +++ b/crypto/pkcs12/p12_key.c @@ -140,7 +140,8 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, I = OPENSSL_malloc(Ilen); Ij = BN_new(); Bpl1 = BN_new(); - if (!D || !Ai || !B || !I || !Ij || !Bpl1) + if (D == NULL || Ai == NULL || B == NULL || I == NULL || Ij == NULL + || Bpl1 == NULL) goto err; for (i = 0; i < v; i++) D[i] = id; diff --git a/crypto/pkcs12/p12_p8e.c b/crypto/pkcs12/p12_p8e.c index 552f2f0d61..c60d124fcb 100644 --- a/crypto/pkcs12/p12_p8e.c +++ b/crypto/pkcs12/p12_p8e.c @@ -104,7 +104,7 @@ X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen, return NULL; } - if (!(p8 = X509_SIG_new())) { + if ((p8 = X509_SIG_new()) == NULL) { PKCS12err(PKCS12_F_PKCS8_SET0_PBE, ERR_R_MALLOC_FAILURE); ASN1_OCTET_STRING_free(enckey); return NULL; diff --git a/crypto/pkcs7/pk7_attr.c b/crypto/pkcs7/pk7_attr.c index ef2386ba3c..31585258d2 100644 --- a/crypto/pkcs7/pk7_attr.c +++ b/crypto/pkcs7/pk7_attr.c @@ -154,7 +154,7 @@ int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, { ASN1_OCTET_STRING *os; os = ASN1_OCTET_STRING_new(); - if (!os) + if (os == NULL) return 0; if (!ASN1_STRING_set(os, md, mdlen) || !PKCS7_add_signed_attribute(si, NID_pkcs9_messageDigest, diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c index b3b4ae360a..df8329419d 100644 --- a/crypto/pkcs7/pk7_doit.c +++ b/crypto/pkcs7/pk7_doit.c @@ -567,7 +567,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) /* Generate random key as MMA defence */ tkeylen = EVP_CIPHER_CTX_key_length(evp_ctx); tkey = OPENSSL_malloc(tkeylen); - if (!tkey) + if (tkey == NULL) goto err; if (EVP_CIPHER_CTX_rand_key(evp_ctx, tkey) <= 0) goto err; @@ -614,6 +614,8 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) bio = BIO_new_mem_buf(data_body->data, data_body->length); else { bio = BIO_new(BIO_s_mem()); + if (bio == NULL) + goto err; BIO_set_mem_eof_return(bio, 0); } if (bio == NULL) @@ -717,9 +719,9 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio) /* XXXXXXXXXXXXXXXX */ si_sk = p7->d.signed_and_enveloped->signer_info; os = p7->d.signed_and_enveloped->enc_data->enc_data; - if (!os) { + if (os == NULL) { os = ASN1_OCTET_STRING_new(); - if (!os) { + if (os == NULL) { PKCS7err(PKCS7_F_PKCS7_DATAFINAL, ERR_R_MALLOC_FAILURE); goto err; } @@ -729,9 +731,9 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio) case NID_pkcs7_enveloped: /* XXXXXXXXXXXXXXXX */ os = p7->d.enveloped->enc_data->enc_data; - if (!os) { + if (os == NULL) { os = ASN1_OCTET_STRING_new(); - if (!os) { + if (os == NULL) { PKCS7err(PKCS7_F_PKCS7_DATAFINAL, ERR_R_MALLOC_FAILURE); goto err; } @@ -799,7 +801,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio) unsigned int abuflen; abuflen = EVP_PKEY_size(si->pkey); abuf = OPENSSL_malloc(abuflen); - if (!abuf) + if (abuf == NULL) goto err; if (!EVP_SignFinal(&ctx_tmp, abuf, &abuflen, si->pkey)) { @@ -885,7 +887,7 @@ int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si) if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0) goto err; abuf = OPENSSL_malloc(siglen); - if (!abuf) + if (abuf == NULL) goto err; if (EVP_DigestSignFinal(&mctx, abuf, &siglen) <= 0) goto err; diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index 55c90cc4bf..760de52e25 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -195,7 +195,7 @@ static size_t drbg_get_entropy(DRBG_CTX *ctx, unsigned char **pout, /* Round up request to multiple of block size */ min_len = ((min_len + 19) / 20) * 20; *pout = OPENSSL_malloc(min_len); - if (!*pout) + if (*pout == NULL) return 0; if (RAND_OpenSSL()->bytes(*pout, min_len) <= 0) { OPENSSL_free(*pout); diff --git a/crypto/rand/rand_os2.c b/crypto/rand/rand_os2.c index 0397d77c63..d95cd24a3b 100644 --- a/crypto/rand/rand_os2.c +++ b/crypto/rand/rand_os2.c @@ -149,7 +149,7 @@ int RAND_poll(void) if (DosQuerySysState) { char *buffer = OPENSSL_malloc(256 * 1024); - if (!buffer) + if (buffer == NULL) return 0; if (DosQuerySysState(0x1F, 0, 0, 0, buffer, 256 * 1024) == 0) { diff --git a/crypto/rand/rand_win.c b/crypto/rand/rand_win.c index a91014bad3..7bf41616a6 100644 --- a/crypto/rand/rand_win.c +++ b/crypto/rand/rand_win.c @@ -712,7 +712,7 @@ static void readscreen(void) bi.biClrImportant = 0; bmbits = OPENSSL_malloc(size); - if (bmbits) { + if (bmbits != NULL) { /* Now go through the whole screen, repeatedly grabbing n lines */ for (y = 0; y < h - n; y += n) { unsigned char md[MD_DIGEST_LENGTH]; diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index 63f88e58aa..bae43f23bf 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -449,7 +449,7 @@ static int rsa_md_to_algor(X509_ALGOR **palg, const EVP_MD *md) if (EVP_MD_type(md) == NID_sha1) return 1; *palg = X509_ALGOR_new(); - if (!*palg) + if (*palg == NULL) return 0; X509_ALGOR_set_md(*palg, md); return 1; @@ -469,7 +469,7 @@ static int rsa_md_to_mgf1(X509_ALGOR **palg, const EVP_MD *mgf1md) if (!ASN1_item_pack(algtmp, ASN1_ITEM_rptr(X509_ALGOR), &stmp)) goto err; *palg = X509_ALGOR_new(); - if (!*palg) + if (*palg == NULL) goto err; X509_ALGOR_set0(*palg, OBJ_nid2obj(NID_mgf1), V_ASN1_SEQUENCE, stmp); stmp = NULL; @@ -542,11 +542,11 @@ static ASN1_STRING *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx) saltlen--; } pss = RSA_PSS_PARAMS_new(); - if (!pss) + if (pss == NULL) goto err; if (saltlen != 20) { pss->saltLength = ASN1_INTEGER_new(); - if (!pss->saltLength) + if (pss->saltLength == NULL) goto err; if (!ASN1_INTEGER_set(pss->saltLength, saltlen)) goto err; @@ -876,7 +876,7 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri) if (labellen < 0) goto err; oaep = RSA_OAEP_PARAMS_new(); - if (!oaep) + if (oaep == NULL) goto err; if (!rsa_md_to_algor(&oaep->hashFunc, md)) goto err; @@ -885,9 +885,9 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri) if (labellen > 0) { ASN1_OCTET_STRING *los = ASN1_OCTET_STRING_new(); oaep->pSourceFunc = X509_ALGOR_new(); - if (!oaep->pSourceFunc) + if (oaep->pSourceFunc == NULL) goto err; - if (!los) + if (los == NULL) goto err; if (!ASN1_OCTET_STRING_set(los, label, labellen)) { ASN1_OCTET_STRING_free(los); diff --git a/crypto/rsa/rsa_asn1.c b/crypto/rsa/rsa_asn1.c index 8061aed5a9..16c40e38fd 100644 --- a/crypto/rsa/rsa_asn1.c +++ b/crypto/rsa/rsa_asn1.c @@ -70,7 +70,7 @@ static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, { if (operation == ASN1_OP_NEW_PRE) { *pval = (ASN1_VALUE *)RSA_new(); - if (*pval) + if (*pval != NULL) return 2; return 0; } else if (operation == ASN1_OP_FREE_PRE) { diff --git a/crypto/rsa/rsa_crpt.c b/crypto/rsa/rsa_crpt.c index 3c4fd67714..4df1662320 100644 --- a/crypto/rsa/rsa_crpt.c +++ b/crypto/rsa/rsa_crpt.c @@ -199,7 +199,7 @@ BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx) if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) { /* Set BN_FLG_CONSTTIME flag */ local_n = n = BN_new(); - if (!local_n) { + if (local_n == NULL) { RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/rsa/rsa_depr.c b/crypto/rsa/rsa_depr.c index b76781b4eb..5bd0275856 100644 --- a/crypto/rsa/rsa_depr.c +++ b/crypto/rsa/rsa_depr.c @@ -78,7 +78,7 @@ RSA *RSA_generate_key(int bits, unsigned long e_value, RSA *rsa = RSA_new(); BIGNUM *e = BN_new(); - if (!cb || !rsa || !e) + if (cb == NULL || rsa == NULL || e == NULL) goto err; /* diff --git a/crypto/rsa/rsa_eay.c b/crypto/rsa/rsa_eay.c index a41964d8a9..a09fbf05b4 100644 --- a/crypto/rsa/rsa_eay.c +++ b/crypto/rsa/rsa_eay.c @@ -184,7 +184,7 @@ static int RSA_eay_public_encrypt(int flen, const unsigned char *from, ret = BN_CTX_get(ctx); num = BN_num_bytes(rsa->n); buf = OPENSSL_malloc(num); - if (!f || !ret || !buf) { + if (f == NULL || ret == NULL || buf == NULL) { RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -361,7 +361,7 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from, ret = BN_CTX_get(ctx); num = BN_num_bytes(rsa->n); buf = OPENSSL_malloc(num); - if (!f || !ret || !buf) { + if (f == NULL || ret == NULL || buf == NULL) { RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -422,7 +422,7 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from, if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) { local_d = d = BN_new(); - if (!d) { + if (d == NULL) { RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -500,7 +500,7 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, ret = BN_CTX_get(ctx); num = BN_num_bytes(rsa->n); buf = OPENSSL_malloc(num); - if (!f || !ret || !buf) { + if (f == NULL || ret == NULL || buf == NULL) { RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -554,7 +554,7 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) { local_d = d = BN_new(); - if (!d) { + if (d == NULL) { RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -646,7 +646,7 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from, ret = BN_CTX_get(ctx); num = BN_num_bytes(rsa->n); buf = OPENSSL_malloc(num); - if (!f || !ret || !buf) { + if (f == NULL || ret == NULL || buf == NULL) { RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, ERR_R_MALLOC_FAILURE); goto err; } @@ -723,7 +723,8 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) local_dmq1 = BN_new(); local_c = BN_new(); local_r1 = BN_new(); - if (!local_dmp1 || !local_dmq1 || !local_c || !local_r1) + if (local_dmp1 == NULL + || local_dmq1 == NULL || local_c == NULL || local_r1 == NULL) goto err; r1 = BN_CTX_get(ctx); @@ -740,12 +741,12 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) */ if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) { local_p = p = BN_new(); - if (!p) + if (p == NULL) goto err; BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME); local_q = q = BN_new(); - if (!q) { + if (q == NULL) { BN_free(local_p); goto err; } @@ -880,7 +881,7 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) { local_d = d = BN_new(); - if (!d) + if (d == NULL) goto err; BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME); } else diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c index e40186aced..dc3e5d3dcd 100644 --- a/crypto/rsa/rsa_gen.c +++ b/crypto/rsa/rsa_gen.c @@ -97,7 +97,7 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, local_r0 = BN_new(); local_d = BN_new(); local_p = BN_new(); - if (!local_r0 || !local_d || !local_p) + if (local_r0 == NULL || local_d == NULL || local_p == NULL) goto err; ctx = BN_CTX_new(); diff --git a/crypto/rsa/rsa_pmeth.c b/crypto/rsa/rsa_pmeth.c index dd7b7dd557..a2022bb6a2 100644 --- a/crypto/rsa/rsa_pmeth.c +++ b/crypto/rsa/rsa_pmeth.c @@ -98,7 +98,7 @@ static int pkey_rsa_init(EVP_PKEY_CTX *ctx) { RSA_PKEY_CTX *rctx; rctx = OPENSSL_zalloc(sizeof(*rctx)); - if (!rctx) + if (rctx == NULL) return 0; rctx->nbits = 1024; rctx->pad_mode = RSA_PKCS1_PADDING; @@ -141,7 +141,7 @@ static int setup_tbuf(RSA_PKEY_CTX *ctx, EVP_PKEY_CTX *pk) if (ctx->tbuf) return 1; ctx->tbuf = OPENSSL_malloc(EVP_PKEY_size(pk->pkey)); - if (!ctx->tbuf) + if (ctx->tbuf == NULL) return 0; return 1; } @@ -634,17 +634,17 @@ static int pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) RSA_PKEY_CTX *rctx = ctx->data; BN_GENCB *pcb; int ret; - if (!rctx->pub_exp) { + if (rctx->pub_exp == NULL) { rctx->pub_exp = BN_new(); - if (!rctx->pub_exp || !BN_set_word(rctx->pub_exp, RSA_F4)) + if (rctx->pub_exp == NULL || !BN_set_word(rctx->pub_exp, RSA_F4)) return 0; } rsa = RSA_new(); - if (!rsa) + if (rsa == NULL) return 0; if (ctx->pkey_gencb) { pcb = BN_GENCB_new(); - if (!pcb) { + if (pcb == NULL) { RSA_free(rsa); return 0; } diff --git a/crypto/rsa/rsa_prn.c b/crypto/rsa/rsa_prn.c index 3d8c800e02..fd29280124 100644 --- a/crypto/rsa/rsa_prn.c +++ b/crypto/rsa/rsa_prn.c @@ -84,7 +84,7 @@ int RSA_print(BIO *bp, const RSA *x, int off) EVP_PKEY *pk; int ret; pk = EVP_PKEY_new(); - if (!pk || !EVP_PKEY_set1_RSA(pk, (RSA *)x)) + if (pk == NULL || !EVP_PKEY_set1_RSA(pk, (RSA *)x)) return 0; ret = EVP_PKEY_print_private(bp, pk, off, NULL); EVP_PKEY_free(pk); diff --git a/crypto/rsa/rsa_pss.c b/crypto/rsa/rsa_pss.c index 03d900c320..95bf6b0d8c 100644 --- a/crypto/rsa/rsa_pss.c +++ b/crypto/rsa/rsa_pss.c @@ -134,7 +134,7 @@ int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, maskedDBLen = emLen - hLen - 1; H = EM + maskedDBLen; DB = OPENSSL_malloc(maskedDBLen); - if (!DB) { + if (DB == NULL) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, ERR_R_MALLOC_FAILURE); goto err; } @@ -231,7 +231,7 @@ int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, } if (sLen > 0) { salt = OPENSSL_malloc(sLen); - if (!salt) { + if (salt == NULL) { RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1, ERR_R_MALLOC_FAILURE); goto err; diff --git a/crypto/rsa/rsa_x931g.c b/crypto/rsa/rsa_x931g.c index e158c6d443..24d3cb9c23 100644 --- a/crypto/rsa/rsa_x931g.c +++ b/crypto/rsa/rsa_x931g.c @@ -78,7 +78,7 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, goto err; ctx = BN_CTX_new(); - if (!ctx) + if (ctx == NULL) goto err; BN_CTX_start(ctx); @@ -101,9 +101,9 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, * test programs to output selective parameters. */ - if (Xp && !rsa->p) { + if (Xp && rsa->p == NULL) { rsa->p = BN_new(); - if (!rsa->p) + if (rsa->p == NULL) goto err; if (!BN_X931_derive_prime_ex(rsa->p, p1, p2, @@ -111,16 +111,16 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, goto err; } - if (Xq && !rsa->q) { + if (Xq && rsa->q == NULL) { rsa->q = BN_new(); - if (!rsa->q) + if (rsa->q == NULL) goto err; if (!BN_X931_derive_prime_ex(rsa->q, q1, q2, Xq, Xq1, Xq2, e, ctx, cb)) goto err; } - if (!rsa->p || !rsa->q) { + if (rsa->p == NULL || rsa->q == NULL) { BN_CTX_end(ctx); BN_CTX_free(ctx); return 2; @@ -153,7 +153,7 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, goto err; /* LCM((p-1)(q-1)) */ ctx2 = BN_CTX_new(); - if (!ctx2) + if (ctx2 == NULL) goto err; rsa->d = BN_mod_inverse(NULL, rsa->e, r0, ctx2); /* d */ @@ -196,7 +196,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_CTX *ctx = NULL; ctx = BN_CTX_new(); - if (!ctx) + if (ctx == NULL) goto error; BN_CTX_start(ctx); @@ -207,7 +207,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, rsa->p = BN_new(); rsa->q = BN_new(); - if (!rsa->p || !rsa->q) + if (rsa->p == NULL || rsa->q == NULL) goto error; /* Generate two primes from Xp, Xq */ diff --git a/crypto/store/str_lib.c b/crypto/store/str_lib.c index 1b554c3f56..c2e6b8e8d1 100644 --- a/crypto/store/str_lib.c +++ b/crypto/store/str_lib.c @@ -270,7 +270,7 @@ int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[], store_object, STORE_R_NO_STORE_OBJECT_FUNCTION); object = STORE_OBJECT_new(); - if (!object) { + if (object == NULL) { STOREerr(STORE_F_STORE_STORE_CERTIFICATE, ERR_R_MALLOC_FAILURE); return 0; } @@ -471,12 +471,12 @@ int STORE_store_private_key(STORE *s, EVP_PKEY *data, store_object, STORE_R_NO_STORE_OBJECT_FUNCTION); object = STORE_OBJECT_new(); - if (!object) { + if (object == NULL) { STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, ERR_R_MALLOC_FAILURE); return 0; } object->data.key = EVP_PKEY_new(); - if (!object->data.key) { + if (object->data.key == NULL) { STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, ERR_R_MALLOC_FAILURE); return 0; } @@ -655,12 +655,12 @@ int STORE_store_public_key(STORE *s, EVP_PKEY *data, store_object, STORE_R_NO_STORE_OBJECT_FUNCTION); object = STORE_OBJECT_new(); - if (!object) { + if (object == NULL) { STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, ERR_R_MALLOC_FAILURE); return 0; } object->data.key = EVP_PKEY_new(); - if (!object->data.key) { + if (object->data.key == NULL) { STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, ERR_R_MALLOC_FAILURE); return 0; } @@ -862,7 +862,7 @@ int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[], store_object, STORE_R_NO_STORE_OBJECT_FUNCTION); object = STORE_OBJECT_new(); - if (!object) { + if (object == NULL) { STOREerr(STORE_F_STORE_STORE_CRL, ERR_R_MALLOC_FAILURE); return 0; } @@ -991,7 +991,7 @@ int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[], store_object, STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION); object = STORE_OBJECT_new(); - if (!object) { + if (object == NULL) { STOREerr(STORE_F_STORE_STORE_NUMBER, ERR_R_MALLOC_FAILURE); return 0; } @@ -1075,7 +1075,7 @@ int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[], store_object, STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION); object = STORE_OBJECT_new(); - if (!object) { + if (object == NULL) { STOREerr(STORE_F_STORE_STORE_ARBITRARY, ERR_R_MALLOC_FAILURE); return 0; } @@ -1449,7 +1449,7 @@ void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes) { if (attributes) { struct attr_list_ctx_st *context = OPENSSL_malloc(sizeof(*context)); - if (context) + if (context != NULL) context->attributes = attributes; else STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_MALLOC_FAILURE); @@ -1473,7 +1473,7 @@ STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle) case STORE_ATTR_FRIENDLYNAME: case STORE_ATTR_EMAIL: case STORE_ATTR_FILENAME: - if (!attrs) + if (attrs == NULL) attrs = STORE_ATTR_INFO_new(); if (attrs == NULL) { STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, @@ -1490,7 +1490,7 @@ STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle) case STORE_ATTR_SUBJECTKEYID: case STORE_ATTR_ISSUERSERIALHASH: case STORE_ATTR_CERTHASH: - if (!attrs) + if (attrs == NULL) attrs = STORE_ATTR_INFO_new(); if (attrs == NULL) { STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, @@ -1504,7 +1504,7 @@ STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle) break; case STORE_ATTR_ISSUER: case STORE_ATTR_SUBJECT: - if (!attrs) + if (attrs == NULL) attrs = STORE_ATTR_INFO_new(); if (attrs == NULL) { STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, @@ -1516,7 +1516,7 @@ STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle) context->attributes->value); break; case STORE_ATTR_SERIAL: - if (!attrs) + if (attrs == NULL) attrs = STORE_ATTR_INFO_new(); if (attrs == NULL) { STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, diff --git a/crypto/store/str_mem.c b/crypto/store/str_mem.c index 1736f7903f..add76e718a 100644 --- a/crypto/store/str_mem.c +++ b/crypto/store/str_mem.c @@ -248,7 +248,7 @@ static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type, void *attribute_context = NULL; STORE_ATTR_INFO *attrs = NULL; - if (!context) { + if (context == NULL) { STOREerr(STORE_F_MEM_LIST_START, ERR_R_MALLOC_FAILURE); return 0; } @@ -263,7 +263,7 @@ static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type, if (context->search_attributes == NULL) { context->search_attributes = sk_STORE_ATTR_INFO_new(STORE_ATTR_INFO_compare); - if (!context->search_attributes) { + if (context->search_attributes == NULL) { STOREerr(STORE_F_MEM_LIST_START, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/store/str_meth.c b/crypto/store/str_meth.c index c030198841..f9ce8bb4e7 100644 --- a/crypto/store/str_meth.c +++ b/crypto/store/str_meth.c @@ -65,7 +65,7 @@ STORE_METHOD *STORE_create_method(char *name) { STORE_METHOD *store_method = OPENSSL_zalloc(sizeof(*store_method)); - if (store_method) + if (store_method != NULL) store_method->name = BUF_strdup(name); return store_method; } diff --git a/crypto/ts/ts_lib.c b/crypto/ts/ts_lib.c index 0b4ee03608..fb871d2a0f 100644 --- a/crypto/ts/ts_lib.c +++ b/crypto/ts/ts_lib.c @@ -73,7 +73,7 @@ int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num) char *hex; num_bn = BN_new(); - if (!num_bn) + if (num_bn == NULL) return -1; ASN1_INTEGER_to_BN(num, num_bn); if ((hex = BN_bn2hex(num_bn))) { diff --git a/crypto/ts/ts_rsp_sign.c b/crypto/ts/ts_rsp_sign.c index dd6591db13..c7738b8a51 100644 --- a/crypto/ts/ts_rsp_sign.c +++ b/crypto/ts/ts_rsp_sign.c @@ -96,7 +96,7 @@ static ASN1_INTEGER *def_serial_cb(struct TS_resp_ctx *ctx, void *data) { ASN1_INTEGER *serial = ASN1_INTEGER_new(); - if (!serial) + if (serial == NULL) goto err; if (!ASN1_INTEGER_set(serial, 1)) goto err; diff --git a/crypto/ts/ts_verify_ctx.c b/crypto/ts/ts_verify_ctx.c index 48deb2ed3b..35335fa43a 100644 --- a/crypto/ts/ts_verify_ctx.c +++ b/crypto/ts/ts_verify_ctx.c @@ -66,7 +66,7 @@ TS_VERIFY_CTX *TS_VERIFY_CTX_new(void) { TS_VERIFY_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); - if (!ctx) + if (ctx == NULL) TSerr(TS_F_TS_VERIFY_CTX_NEW, ERR_R_MALLOC_FAILURE); return ctx; } diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c index 6837bd6872..9440a857c4 100644 --- a/crypto/ui/ui_lib.c +++ b/crypto/ui/ui_lib.c @@ -138,7 +138,7 @@ static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt, } else if ((type == UIT_PROMPT || type == UIT_VERIFY || type == UIT_BOOLEAN) && result_buf == NULL) { UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, UI_R_NO_RESULT_BUFFER); - } else if ((ret = OPENSSL_malloc(sizeof(*ret)))) { + } else if ((ret = OPENSSL_malloc(sizeof(*ret))) != NULL) { ret->out_string = prompt; ret->flags = prompt_freeable ? OUT_STRING_FREEABLE : 0; ret->input_flags = input_flags; @@ -581,7 +581,7 @@ UI_METHOD *UI_create_method(char *name) { UI_METHOD *ui_method = OPENSSL_zalloc(sizeof(*ui_method)); - if (ui_method) + if (ui_method != NULL) ui_method->name = BUF_strdup(name); return ui_method; } diff --git a/crypto/ui/ui_util.c b/crypto/ui/ui_util.c index b18e2a2a42..b1d76f4656 100644 --- a/crypto/ui/ui_util.c +++ b/crypto/ui/ui_util.c @@ -83,7 +83,7 @@ int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, return -1; ui = UI_new(); - if (ui) { + if (ui != NULL) { ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1); if (ok >= 0 && verify) ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1, buf); diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c index 3dd04d04aa..8310bc4701 100644 --- a/crypto/x509/by_dir.c +++ b/crypto/x509/by_dir.c @@ -229,12 +229,12 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) } } ent = OPENSSL_malloc(sizeof(*ent)); - if (!ent) + if (ent == NULL) return 0; ent->dir_type = type; ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); ent->dir = OPENSSL_malloc((unsigned int)len + 1); - if (!ent->dir || !ent->hashes) { + if (ent->dir == NULL || ent->hashes == NULL) { by_dir_entry_free(ent); return 0; } diff --git a/crypto/x509/x509_lu.c b/crypto/x509/x509_lu.c index 2bcac35eed..b61d757d3c 100644 --- a/crypto/x509/x509_lu.c +++ b/crypto/x509/x509_lu.c @@ -183,21 +183,26 @@ X509_STORE *X509_STORE_new(void) if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) return NULL; - ret->objs = sk_X509_OBJECT_new(x509_object_cmp); + if ((ret->objs = sk_X509_OBJECT_new(x509_object_cmp)) == NULL) + goto err; ret->cache = 1; - ret->get_cert_methods = sk_X509_LOOKUP_new_null(); + if ((ret->get_cert_methods = sk_X509_LOOKUP_new_null()) == NULL) + goto err; if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) - return NULL; + goto err; - if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data)) { - sk_X509_OBJECT_free(ret->objs); - OPENSSL_free(ret); - return NULL; - } + if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data)) + goto err; ret->references = 1; return ret; +err: + X509_VERIFY_PARAM_free(ret->param); + sk_X509_OBJECT_free(ret->objs); + sk_X509_LOOKUP_free(ret->get_cert_methods); + OPENSSL_free(ret); + return NULL; } static void cleanup(X509_OBJECT *a) diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index 1ae3675e2e..051751f7b3 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c @@ -2049,7 +2049,7 @@ X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer, } /* Create new CRL */ crl = X509_CRL_new(); - if (!crl || !X509_CRL_set_version(crl, 1)) + if (crl == NULL || !X509_CRL_set_version(crl, 1)) goto memerr; /* Set issuer name */ if (!X509_CRL_set_issuer_name(crl, X509_CRL_get_issuer(newer))) @@ -2267,7 +2267,7 @@ X509_STORE_CTX *X509_STORE_CTX_new(void) { X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/x509/x509_vpm.c b/crypto/x509/x509_vpm.c index cf8784d5fb..ceb79e2844 100644 --- a/crypto/x509/x509_vpm.c +++ b/crypto/x509/x509_vpm.c @@ -163,10 +163,10 @@ X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void) X509_VERIFY_PARAM_ID *paramid; param = OPENSSL_zalloc(sizeof(*param)); - if (!param) + if (param == NULL) return NULL; param->id = paramid = OPENSSL_zalloc(sizeof(*paramid)); - if (!paramid) { + if (paramid == NULL) { OPENSSL_free(param); return NULL; } @@ -580,9 +580,9 @@ int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param) { int idx; X509_VERIFY_PARAM *ptmp; - if (!param_table) { + if (param_table == NULL) { param_table = sk_X509_VERIFY_PARAM_new(param_cmp); - if (!param_table) + if (param_table == NULL) return 0; } else { idx = sk_X509_VERIFY_PARAM_find(param_table, param); diff --git a/crypto/x509/x509spki.c b/crypto/x509/x509spki.c index 116f78800f..df27bf338a 100644 --- a/crypto/x509/x509spki.c +++ b/crypto/x509/x509spki.c @@ -111,7 +111,7 @@ char *NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) der_len = i2d_NETSCAPE_SPKI(spki, NULL); der_spki = OPENSSL_malloc(der_len); b64_str = OPENSSL_malloc(der_len * 2); - if (!der_spki || !b64_str) { + if (der_spki == NULL || b64_str == NULL) { X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); OPENSSL_free(der_spki); OPENSSL_free(b64_str); diff --git a/crypto/x509/x_crl.c b/crypto/x509/x_crl.c index 79fa5ca34f..435de80810 100644 --- a/crypto/x509/x_crl.c +++ b/crypto/x509/x_crl.c @@ -357,9 +357,9 @@ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) { X509_CRL_INFO *inf; inf = &crl->crl; - if (!inf->revoked) + if (inf->revoked == NULL) inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); - if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { + if (inf->revoked == NULL || !sk_X509_REVOKED_push(inf->revoked, rev)) { ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); return 0; } @@ -478,7 +478,7 @@ X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init) (X509_CRL *crl), { X509_CRL_METHOD *m; m = OPENSSL_malloc(sizeof(*m)); - if (!m) + if (m == NULL) return NULL; m->crl_init = crl_init; m->crl_free = crl_free; diff --git a/crypto/x509/x_name.c b/crypto/x509/x_name.c index f52b91f06f..2895734cc1 100644 --- a/crypto/x509/x_name.c +++ b/crypto/x509/x_name.c @@ -135,7 +135,7 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) { X509_NAME *ret = OPENSSL_zalloc(sizeof(*ret)); - if (!ret) + if (ret == NULL) goto memerr; if ((ret->entries = sk_X509_NAME_ENTRY_new_null()) == NULL) goto memerr; @@ -361,7 +361,7 @@ static int x509_name_canon(X509_NAME *a) set = entry->set; } tmpentry = X509_NAME_ENTRY_new(); - if (!tmpentry) + if (tmpentry == NULL) goto err; tmpentry->object = OBJ_dup(entry->object); if (!asn1_string_canon(tmpentry->value, entry->value)) @@ -377,7 +377,7 @@ static int x509_name_canon(X509_NAME *a) p = OPENSSL_malloc(a->canon_enclen); - if (!p) + if (p == NULL) goto err; a->canon_enc = p; diff --git a/crypto/x509v3/pcy_cache.c b/crypto/x509v3/pcy_cache.c index 41a748d872..97ebb3602d 100644 --- a/crypto/x509v3/pcy_cache.c +++ b/crypto/x509v3/pcy_cache.c @@ -84,12 +84,12 @@ static int policy_cache_create(X509 *x, if (sk_POLICYINFO_num(policies) == 0) goto bad_policy; cache->data = sk_X509_POLICY_DATA_new(policy_data_cmp); - if (!cache->data) + if (cache->data == NULL) goto bad_policy; for (i = 0; i < sk_POLICYINFO_num(policies); i++) { policy = sk_POLICYINFO_value(policies, i); data = policy_data_new(policy, NULL, crit); - if (!data) + if (data == NULL) goto bad_policy; /* * Duplicate policy OIDs are illegal: reject if matches found. @@ -129,7 +129,7 @@ static int policy_cache_new(X509 *x) POLICY_MAPPINGS *ext_pmaps = NULL; int i; cache = OPENSSL_malloc(sizeof(*cache)); - if (!cache) + if (cache == NULL) return 0; cache->anyPolicy = NULL; cache->data = NULL; diff --git a/crypto/x509v3/pcy_data.c b/crypto/x509v3/pcy_data.c index bb2760abc2..1772e3198b 100644 --- a/crypto/x509v3/pcy_data.c +++ b/crypto/x509v3/pcy_data.c @@ -99,10 +99,10 @@ X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, } else id = NULL; ret = OPENSSL_zalloc(sizeof(*ret)); - if (!ret) + if (ret == NULL) return NULL; ret->expected_policy_set = sk_ASN1_OBJECT_new_null(); - if (!ret->expected_policy_set) { + if (ret->expected_policy_set == NULL) { OPENSSL_free(ret); ASN1_OBJECT_free(id); return NULL; diff --git a/crypto/x509v3/pcy_map.c b/crypto/x509v3/pcy_map.c index 4989a816c4..1c58ad4e24 100644 --- a/crypto/x509v3/pcy_map.c +++ b/crypto/x509v3/pcy_map.c @@ -92,15 +92,15 @@ int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps) /* Attempt to find matching policy data */ data = policy_cache_find_data(cache, map->issuerDomainPolicy); /* If we don't have anyPolicy can't map */ - if (!data && !cache->anyPolicy) + if (data == NULL && !cache->anyPolicy) continue; /* Create a NODE from anyPolicy */ - if (!data) { + if (data == NULL) { data = policy_data_new(NULL, map->issuerDomainPolicy, cache->anyPolicy->flags & POLICY_DATA_FLAG_CRITICAL); - if (!data) + if (data == NULL) goto bad_mapping; data->qualifier_set = cache->anyPolicy->qualifier_set; /* diff --git a/crypto/x509v3/pcy_node.c b/crypto/x509v3/pcy_node.c index 64f979a32a..81b4c78bc2 100644 --- a/crypto/x509v3/pcy_node.c +++ b/crypto/x509v3/pcy_node.c @@ -116,7 +116,7 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level, X509_POLICY_NODE *node; node = OPENSSL_zalloc(sizeof(*node)); - if (!node) + if (node == NULL) return NULL; node->data = data; node->parent = parent; @@ -127,9 +127,9 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level, level->anyPolicy = node; } else { - if (!level->nodes) + if (level->nodes == NULL) level->nodes = policy_node_cmp_new(); - if (!level->nodes) + if (level->nodes == NULL) goto node_error; if (!sk_X509_POLICY_NODE_push(level->nodes, node)) goto node_error; @@ -137,9 +137,9 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level, } if (tree) { - if (!tree->extra_data) + if (tree->extra_data == NULL) tree->extra_data = sk_X509_POLICY_DATA_new_null(); - if (!tree->extra_data) + if (tree->extra_data == NULL) goto node_error; if (!sk_X509_POLICY_DATA_push(tree->extra_data, data)) goto node_error; diff --git a/crypto/x509v3/pcy_tree.c b/crypto/x509v3/pcy_tree.c index bbc9ada143..04d7bfc42a 100644 --- a/crypto/x509v3/pcy_tree.c +++ b/crypto/x509v3/pcy_tree.c @@ -220,10 +220,10 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs, /* If we get this far initialize the tree */ tree = OPENSSL_zalloc(sizeof(*tree)); - if (!tree) + if (tree == NULL) return 0; tree->levels = OPENSSL_zalloc(sizeof(*tree->levels) * n); - if (!tree->levels) { + if (tree->levels == NULL) { OPENSSL_free(tree); return 0; } @@ -233,7 +233,7 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs, /* Root data: initialize to anyPolicy */ data = policy_data_new(NULL, OBJ_nid2obj(NID_any_policy), 0); - if (!data || !level_add_node(level, data, NULL, tree)) + if (data == NULL || !level_add_node(level, data, NULL, tree)) goto bad_tree; for (i = n - 2; i >= 0; i--) { @@ -478,9 +478,9 @@ static int tree_prune(X509_POLICY_TREE *tree, X509_POLICY_LEVEL *curr) static int tree_add_auth_node(STACK_OF(X509_POLICY_NODE) **pnodes, X509_POLICY_NODE *pcy) { - if (!*pnodes) { + if (*pnodes == NULL) { *pnodes = policy_node_cmp_new(); - if (!*pnodes) + if (*pnodes == NULL) return 0; } else if (sk_X509_POLICY_NODE_find(*pnodes, pcy) != -1) return 1; @@ -584,7 +584,7 @@ static int tree_calculate_user_set(X509_POLICY_TREE *tree, * from anyPolicy. */ extra = policy_data_new(NULL, oid, node_critical(anyPolicy)); - if (!extra) + if (extra == NULL) return 0; extra->qualifier_set = anyPolicy->data->qualifier_set; extra->flags = POLICY_DATA_FLAG_SHARED_QUALIFIERS diff --git a/crypto/x509v3/v3_cpols.c b/crypto/x509v3/v3_cpols.c index 9331a499da..3268669659 100644 --- a/crypto/x509v3/v3_cpols.c +++ b/crypto/x509v3/v3_cpols.c @@ -187,6 +187,10 @@ static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, goto err; } pol = POLICYINFO_new(); + if (pol == NULL) { + X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE); + goto err; + } pol->policyid = pobj; } if (!sk_POLICYINFO_push(pols, pol)) { diff --git a/crypto/x509v3/v3_crld.c b/crypto/x509v3/v3_crld.c index 49d282e955..3d61fdd038 100644 --- a/crypto/x509v3/v3_crld.c +++ b/crypto/x509v3/v3_crld.c @@ -128,7 +128,7 @@ static int set_dist_point_name(DIST_POINT_NAME **pdp, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *dnsect; X509_NAME *nm; nm = X509_NAME_new(); - if (!nm) + if (nm == NULL) return -1; dnsect = X509V3_get_section(ctx, cnf->value); if (!dnsect) { @@ -162,7 +162,7 @@ static int set_dist_point_name(DIST_POINT_NAME **pdp, X509V3_CTX *ctx, } *pdp = DIST_POINT_NAME_new(); - if (!*pdp) + if (*pdp == NULL) goto err; if (fnm) { (*pdp)->type = 0; @@ -206,9 +206,9 @@ static int set_reasons(ASN1_BIT_STRING **preas, char *value) return 0; for (i = 0; i < sk_CONF_VALUE_num(rsk); i++) { bnam = sk_CONF_VALUE_value(rsk, i)->name; - if (!*preas) { + if (*preas == NULL) { *preas = ASN1_BIT_STRING_new(); - if (!*preas) + if (*preas == NULL) goto err; } for (pbn = reason_flags; pbn->lname; pbn++) { @@ -257,7 +257,7 @@ static DIST_POINT *crldp_from_section(X509V3_CTX *ctx, CONF_VALUE *cnf; DIST_POINT *point = NULL; point = DIST_POINT_new(); - if (!point) + if (point == NULL) goto err; for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { int ret; @@ -418,7 +418,7 @@ static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *name, *val; int i, ret; idp = ISSUING_DIST_POINT_new(); - if (!idp) + if (idp == NULL) goto merr; for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { cnf = sk_CONF_VALUE_value(nval, i); diff --git a/crypto/x509v3/v3_genn.c b/crypto/x509v3/v3_genn.c index b4b8de7ba8..4c3ad0567a 100644 --- a/crypto/x509v3/v3_genn.c +++ b/crypto/x509v3/v3_genn.c @@ -229,7 +229,7 @@ int GENERAL_NAME_set0_othername(GENERAL_NAME *gen, { OTHERNAME *oth; oth = OTHERNAME_new(); - if (!oth) + if (oth == NULL) return 0; oth->type_id = oid; oth->value = value; diff --git a/crypto/x509v3/v3_info.c b/crypto/x509v3/v3_info.c index d1a2455b0a..4e38ad33c0 100644 --- a/crypto/x509v3/v3_info.c +++ b/crypto/x509v3/v3_info.c @@ -126,7 +126,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD i2t_ASN1_OBJECT(objtmp, sizeof objtmp, desc->method); nlen = strlen(objtmp) + strlen(vtmp->name) + 5; ntmp = OPENSSL_malloc(nlen); - if (!ntmp) { + if (ntmp == NULL) { X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS, ERR_R_MALLOC_FAILURE); return NULL; diff --git a/crypto/x509v3/v3_ncons.c b/crypto/x509v3/v3_ncons.c index 3fe20cc718..d3f79baca3 100644 --- a/crypto/x509v3/v3_ncons.c +++ b/crypto/x509v3/v3_ncons.c @@ -121,7 +121,7 @@ static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, GENERAL_SUBTREE *sub = NULL; ncons = NAME_CONSTRAINTS_new(); - if (!ncons) + if (ncons == NULL) goto memerr; for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { val = sk_CONF_VALUE_value(nval, i); @@ -137,11 +137,13 @@ static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, } tval.value = val->value; sub = GENERAL_SUBTREE_new(); + if (sub == NULL) + goto memerr; if (!v2i_GENERAL_NAME_ex(sub->base, method, ctx, &tval, 1)) goto err; - if (!*ptree) + if (*ptree == NULL) *ptree = sk_GENERAL_SUBTREE_new_null(); - if (!*ptree || !sk_GENERAL_SUBTREE_push(*ptree, sub)) + if (*ptree == NULL || !sk_GENERAL_SUBTREE_push(*ptree, sub)) goto memerr; sub = NULL; } diff --git a/crypto/x509v3/v3_pci.c b/crypto/x509v3/v3_pci.c index ad497244df..6b68b961f6 100644 --- a/crypto/x509v3/v3_pci.c +++ b/crypto/x509v3/v3_pci.c @@ -111,7 +111,7 @@ static int process_pci_value(CONF_VALUE *val, long val_len; if (!*policy) { *policy = ASN1_OCTET_STRING_new(); - if (!*policy) { + if (*policy == NULL) { X509V3err(X509V3_F_PROCESS_PCI_VALUE, ERR_R_MALLOC_FAILURE); X509V3_conf_err(val); return 0; @@ -293,7 +293,7 @@ static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method, } pci = PROXY_CERT_INFO_EXTENSION_new(); - if (!pci) { + if (pci == NULL) { X509V3err(X509V3_F_R2I_PCI, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/x509v3/v3_pmaps.c b/crypto/x509v3/v3_pmaps.c index bd80a12294..001f2641a4 100644 --- a/crypto/x509v3/v3_pmaps.c +++ b/crypto/x509v3/v3_pmaps.c @@ -144,7 +144,7 @@ static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, return NULL; } pmap = POLICY_MAPPING_new(); - if (!pmap) { + if (pmap == NULL) { sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free); 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 ef219487b5..26619c5ff2 100644 --- a/crypto/x509v3/v3_prn.c +++ b/crypto/x509v3/v3_prn.c @@ -101,7 +101,7 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, char *tmp; len = strlen(nval->value) + 1; tmp = OPENSSL_malloc(len); - if (tmp) { + if (tmp != NULL) { ascii2ebcdic(tmp, nval->value, len); BIO_printf(out, "%s:%s", nval->name, tmp); OPENSSL_free(tmp); @@ -154,7 +154,7 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, char *tmp; len = strlen(value) + 1; tmp = OPENSSL_malloc(len); - if (tmp) { + if (tmp != NULL) { ascii2ebcdic(tmp, value, len); BIO_printf(out, "%*s%s", indent, "", tmp); OPENSSL_free(tmp); diff --git a/crypto/x509v3/v3_scts.c b/crypto/x509v3/v3_scts.c index 777378cf7e..b5122d249f 100644 --- a/crypto/x509v3/v3_scts.c +++ b/crypto/x509v3/v3_scts.c @@ -180,7 +180,7 @@ static STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, listlen -= sctlen; sct = OPENSSL_malloc(sizeof(*sct)); - if (!sct) + if (sct == NULL) goto err; if (!sk_SCT_push(sk, sct)) { OPENSSL_free(sct); @@ -188,7 +188,7 @@ static STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, } sct->sct = OPENSSL_malloc(sctlen); - if (!sct->sct) + if (sct->sct == NULL) goto err; memcpy(sct->sct, p, sctlen); sct->sct_len = sctlen; diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c index 6494d83bdb..8481749a1f 100644 --- a/crypto/x509v3/v3_utl.c +++ b/crypto/x509v3/v3_utl.c @@ -176,11 +176,15 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value) ASN1_INTEGER *aint; int isneg, ishex; int ret; - if (!value) { + if (value == NULL) { X509V3err(X509V3_F_S2I_ASN1_INTEGER, X509V3_R_INVALID_NULL_VALUE); - return 0; + return NULL; } bn = BN_new(); + if (bn == NULL) { + X509V3err(X509V3_F_S2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); + return NULL; + } if (value[0] == '-') { value++; isneg = 1; @@ -201,7 +205,7 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value) if (!ret || value[ret]) { BN_free(bn); X509V3err(X509V3_F_S2I_ASN1_INTEGER, X509V3_R_BN_DEC2BN_ERROR); - return 0; + return NULL; } if (isneg && BN_is_zero(bn)) @@ -212,7 +216,7 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value) if (!aint) { X509V3err(X509V3_F_S2I_ASN1_INTEGER, X509V3_R_BN_TO_ASN1_INTEGER_ERROR); - return 0; + return NULL; } if (isneg) aint->type |= V_ASN1_NEG; @@ -606,15 +610,15 @@ static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email) return 1; if (!email->data || !email->length) return 1; - if (!*sk) + if (*sk == NULL) *sk = sk_OPENSSL_STRING_new(sk_strcmp); - if (!*sk) + if (*sk == NULL) return 0; /* Don't add duplicates */ if (sk_OPENSSL_STRING_find(*sk, (char *)email->data) != -1) return 1; emtmp = BUF_strdup((char *)email->data); - if (!emtmp || !sk_OPENSSL_STRING_push(*sk, emtmp)) { + if (emtmp == NULL || !sk_OPENSSL_STRING_push(*sk, emtmp)) { X509_email_free(*sk); *sk = NULL; return 0; @@ -1077,7 +1081,7 @@ ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc) return NULL; ret = ASN1_OCTET_STRING_new(); - if (!ret) + if (ret == NULL) return NULL; if (!ASN1_OCTET_STRING_set(ret, ipout, iplen)) { ASN1_OCTET_STRING_free(ret); @@ -1115,7 +1119,7 @@ ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc) goto err; ret = ASN1_OCTET_STRING_new(); - if (!ret) + if (ret == NULL) goto err; if (!ASN1_OCTET_STRING_set(ret, ipout, iplen1 + iplen2)) goto err;