Continue malloc standardisation in engines

Continuing from previous work standardise use of malloc in the engine code.

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
This commit is contained in:
Matt Caswell 2015-10-30 11:22:31 +00:00
parent 96487cddd4
commit 55646005a9
6 changed files with 26 additions and 21 deletions

View 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;
}

View 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);

View 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()

View 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;

View File

@ -192,7 +192,7 @@ static ENGINE *ENGINE_padlock(void)
{
ENGINE *eng = ENGINE_new();
if (!eng) {
if (eng == NULL) {
return NULL;
}

View 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);