Continue malloc standardisation in engines
authorMatt Caswell <matt@openssl.org>
Fri, 30 Oct 2015 11:22:31 +0000 (11:22 +0000)
committerMatt Caswell <matt@openssl.org>
Mon, 9 Nov 2015 22:48:41 +0000 (22:48 +0000)
Continuing from previous work standardise use of malloc in the engine code.

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
engines/e_capi.c
engines/e_chil.c
engines/e_gmp.c
engines/e_ossltest.c
engines/e_padlock.c
engines/e_ubsec.c

index a38592b5f65194bf0ab76b7e75fddddabc78a24e..b2ae577987d6e96bd6c9cc73546553b1d56af4eb 100644 (file)
@@ -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;
     }
index 54c6b913c14287f6f3b40dda66847f3ed1d030af..8696c9ac2c6833bf3cd1878c2aa9bf83cbbc6da9 100644 (file)
@@ -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);
 
index 7888c2b231bd94e51c2ad41f91d04ccaf35506f2..68a8cf82b205443d239b2687f51804298c3ec7ba 100644 (file)
@@ -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()
index e9a071ce65f7738cdb256e92125554216143f0ce..b3b9bc039573af14b4518d7d7e8bb64d1258ad69 100644 (file)
@@ -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;
index df636b519b956c16b7416d9876d42b0e55765b8e..fa323b15abc10de3b9fd8e4874c4e43afea7ba51 100644 (file)
@@ -192,7 +192,7 @@ static ENGINE *ENGINE_padlock(void)
 {
     ENGINE *eng = ENGINE_new();
 
-    if (!eng) {
+    if (eng == NULL) {
         return NULL;
     }
 
index ef070b04db93992dbf3bd7bd705ed6b7358a5d3f..eefd37f3ad32c433fa590c430367a1a7f0c4d728 100644 (file)
@@ -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);