From 55646005a9ce3c85e394c6afae5f6ed6045494c6 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Fri, 30 Oct 2015 11:22:31 +0000 Subject: [PATCH] Continue malloc standardisation in engines Continuing from previous work standardise use of malloc in the engine code. Reviewed-by: Kurt Roeckx --- engines/e_capi.c | 23 ++++++++++++----------- engines/e_chil.c | 10 +++++++--- engines/e_gmp.c | 6 +++--- engines/e_ossltest.c | 4 ++-- engines/e_padlock.c | 2 +- engines/e_ubsec.c | 2 +- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/engines/e_capi.c b/engines/e_capi.c index a38592b5f6..b2ae577987 100644 --- a/engines/e_capi.c +++ b/engines/e_capi.c @@ -487,7 +487,7 @@ static int capi_init(ENGINE *e) } ctx = capi_ctx_new(); - if (!ctx) + if (ctx == NULL) goto memerr; ENGINE_set_ex_data(e, capi_idx, ctx); @@ -584,7 +584,7 @@ IMPLEMENT_DYNAMIC_CHECK_FN() static ENGINE *engine_capi(void) { ENGINE *ret = ENGINE_new(); - if (!ret) + if (ret == NULL) return NULL; if (!bind_capi(ret)) { ENGINE_free(ret); @@ -643,7 +643,7 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY * key) pubkey = OPENSSL_malloc(len); - if (!pubkey) + if (pubkey == NULL) goto memerr; if (!CryptExportKey(key->key, 0, PUBLICKEYBLOB, 0, pubkey, &len)) { @@ -678,7 +678,7 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY * key) rkey->e = BN_new(); rkey->n = BN_new(); - if (!rkey->e || !rkey->n) + if (rkey->e == NULL || rkey->n == NULL) goto memerr; if (!BN_set_word(rkey->e, rp->pubexp)) @@ -718,7 +718,8 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY * key) dkey->q = BN_new(); dkey->g = BN_new(); dkey->pub_key = BN_new(); - if (!dkey->p || !dkey->q || !dkey->g || !dkey->pub_key) + if (dkey->p == NULL || dkey->q == NULL || dkey->g == NULL + || dkey->pub_key == NULL) goto memerr; if (!lend_tobn(dkey->p, btmp, dsa_plen)) goto memerr; @@ -1006,11 +1007,11 @@ static DSA_SIG *capi_dsa_do_sign(const unsigned char *digest, int dlen, goto err; } else { ret = DSA_SIG_new(); - if (!ret) + if (ret == NULL) goto err; ret->r = BN_new(); ret->s = BN_new(); - if (!ret->r || !ret->s) + if (ret->r == NULL || ret->s == NULL) goto err; if (!lend_tobn(ret->r, csigbuf, 20) || !lend_tobn(ret->s, csigbuf + 20, 20)) { @@ -1087,7 +1088,7 @@ static char *wide_to_asc(LPCWSTR wstr) return NULL; } str = OPENSSL_malloc(sz); - if (!str) { + if (str == NULL) { CAPIerr(CAPI_F_WIDE_TO_ASC, ERR_R_MALLOC_FAILURE); return NULL; } @@ -1201,7 +1202,7 @@ static int capi_list_containers(CAPI_CTX * ctx, BIO *out) if (buflen == 0) buflen = 1024; cname = OPENSSL_malloc(buflen); - if (!cname) { + if (cname == NULL) { CAPIerr(CAPI_F_CAPI_LIST_CONTAINERS, ERR_R_MALLOC_FAILURE); goto err; } @@ -1251,7 +1252,7 @@ static CRYPT_KEY_PROV_INFO *capi_get_prov_info(CAPI_CTX * ctx, PCCERT_CONTEXT ce (cert, CERT_KEY_PROV_INFO_PROP_ID, NULL, &len)) return NULL; pinfo = OPENSSL_malloc(len); - if (!pinfo) { + if (pinfo == NULL) { CAPIerr(CAPI_F_CAPI_GET_PROV_INFO, ERR_R_MALLOC_FAILURE); return NULL; } @@ -1581,7 +1582,7 @@ static CAPI_CTX *capi_ctx_new(void) { CAPI_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); - if (!ctx) { + if (ctx == NULL) { CAPIerr(CAPI_F_CAPI_CTX_NEW, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/engines/e_chil.c b/engines/e_chil.c index 54c6b913c1..8696c9ac2c 100644 --- a/engines/e_chil.c +++ b/engines/e_chil.c @@ -406,7 +406,7 @@ static int bind_helper(ENGINE *e) static ENGINE *engine_chil(void) { ENGINE *ret = ENGINE_new(); - if (!ret) + if (ret == NULL) return NULL; if (!bind_helper(ret)) { ENGINE_free(ret); @@ -780,7 +780,7 @@ static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id, } # ifndef OPENSSL_NO_RSA hptr = OPENSSL_malloc(sizeof(*hptr)); - if (!hptr) { + if (hptr == NULL) { HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, ERR_R_MALLOC_FAILURE); goto err; } @@ -827,10 +827,14 @@ static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id, bn_fix_top(rtmp->n); res = EVP_PKEY_new(); + if (res == NULL) { + HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, HWCRHK_R_CHIL_ERROR); + goto err; + } EVP_PKEY_assign_RSA(res, rtmp); # endif - if (!res) + if (res == NULL) HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED); diff --git a/engines/e_gmp.c b/engines/e_gmp.c index 7888c2b231..68a8cf82b2 100644 --- a/engines/e_gmp.c +++ b/engines/e_gmp.c @@ -186,7 +186,7 @@ static int bind_helper(ENGINE *e) static ENGINE *engine_gmp(void) { ENGINE *ret = ENGINE_new(); - if (!ret) + if (ret == NULL) return NULL; if (!bind_helper(ret)) { ENGINE_free(ret); @@ -296,7 +296,7 @@ static int gmp2bn(mpz_t g, BIGNUM *bn) } else { int toret; char *tmpchar = OPENSSL_malloc(mpz_sizeinbase(g, 16) + 10); - if (!tmpchar) + if (tmpchar == NULL) return 0; mpz_get_str(tmpchar, 16, g); toret = BN_hex2bn(&bn, tmpchar); @@ -326,7 +326,7 @@ static E_GMP_RSA_CTX *e_gmp_get_rsa(RSA *rsa) if (hptr) return hptr; hptr = OPENSSL_malloc(sizeof(*hptr)); - if (!hptr) + if (hptr == NULL) return NULL; /* * These inits could probably be replaced by more intelligent mpz_init2() diff --git a/engines/e_ossltest.c b/engines/e_ossltest.c index e9a071ce65..b3b9bc0395 100644 --- a/engines/e_ossltest.c +++ b/engines/e_ossltest.c @@ -257,7 +257,7 @@ IMPLEMENT_DYNAMIC_CHECK_FN() static ENGINE *engine_ossltest(void) { ENGINE *ret = ENGINE_new(); - if (!ret) + if (ret == NULL) return NULL; if (!bind_ossltest(ret)) { ENGINE_free(ret); @@ -505,7 +505,7 @@ int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, * run time */ ctx->cipher_data = OPENSSL_zalloc(EVP_aes_128_cbc()->ctx_size); - if (!ctx->cipher_data) { + if (ctx->cipher_data == NULL) { OSSLTESTerr(OSSLTEST_F_OSSLTEST_AES128_INIT_KEY, ERR_R_MALLOC_FAILURE); return 0; diff --git a/engines/e_padlock.c b/engines/e_padlock.c index df636b519b..fa323b15ab 100644 --- a/engines/e_padlock.c +++ b/engines/e_padlock.c @@ -192,7 +192,7 @@ static ENGINE *ENGINE_padlock(void) { ENGINE *eng = ENGINE_new(); - if (!eng) { + if (eng == NULL) { return NULL; } diff --git a/engines/e_ubsec.c b/engines/e_ubsec.c index ef070b04db..eefd37f3ad 100644 --- a/engines/e_ubsec.c +++ b/engines/e_ubsec.c @@ -265,7 +265,7 @@ static int bind_helper(ENGINE *e) static ENGINE *engine_ubsec(void) { ENGINE *ret = ENGINE_new(); - if (!ret) + if (ret == NULL) return NULL; if (!bind_helper(ret)) { ENGINE_free(ret); -- 2.25.1