Continue standardising malloc style for libcrypto

Continuing from previous commit ensure our style is consistent for malloc
return checks.

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
This commit is contained in:
Matt Caswell 2015-10-30 11:12:26 +00:00
parent a71edf3ba2
commit 90945fa31a
155 changed files with 468 additions and 407 deletions

View File

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

View File

@ -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);
}

View File

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

View File

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

View File

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

View File

@ -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 */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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);
}

View File

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

View File

@ -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. */

View File

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

View File

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

View File

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

View File

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

View File

@ -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);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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,

View File

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

View File

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

View File

@ -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

View File

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

View File

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

View File

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

View File

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

View File

@ -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)

View File

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

View File

@ -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) {

View File

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

View File

@ -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)

View File

@ -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

View File

@ -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) ||

View File

@ -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 */

View File

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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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)) {

View File

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

View File

@ -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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 {

View File

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

View File

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

View File

@ -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.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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);
}

View File

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

View File

@ -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)

View File

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

View File

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

View File

@ -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) {

View File

@ -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))

View File

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

View File

@ -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);
}

View File

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

View File

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

View File

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

View File

@ -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);
}

View File

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

View File

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

View File

@ -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);
}

View File

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

Some files were not shown because too many files have changed in this diff Show More