Fix missing malloc return value checks
During work on a larger change in master a number of locations were identified where return value checks were missing. This backports the relevant fixes. Reviewed-by: Richard Levitte <levitte@openssl.org> (cherry picked from commit 903738ac63e60c10552741e2d6de9753c67e0ff3) Conflicts: crypto/cms/cms_sd.c
This commit is contained in:
parent
c8cc43108d
commit
84d0c40f3f
@ -2514,6 +2514,8 @@ static int do_updatedb(CA_DB *db)
|
|||||||
char **rrow, *a_tm_s;
|
char **rrow, *a_tm_s;
|
||||||
|
|
||||||
a_tm = ASN1_UTCTIME_new();
|
a_tm = ASN1_UTCTIME_new();
|
||||||
|
if (a_tm == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* get actual time and make a string */
|
/* get actual time and make a string */
|
||||||
a_tm = X509_gmtime_adj(a_tm, 0);
|
a_tm = X509_gmtime_adj(a_tm, 0);
|
||||||
|
@ -121,6 +121,9 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
|
|||||||
|
|
||||||
/* Setup algorithm identifier for cipher */
|
/* Setup algorithm identifier for cipher */
|
||||||
encalg = X509_ALGOR_new();
|
encalg = X509_ALGOR_new();
|
||||||
|
if (encalg == NULL) {
|
||||||
|
goto merr;
|
||||||
|
}
|
||||||
EVP_CIPHER_CTX_init(&ctx);
|
EVP_CIPHER_CTX_init(&ctx);
|
||||||
|
|
||||||
if (EVP_EncryptInit_ex(&ctx, kekciph, NULL, NULL, NULL) <= 0) {
|
if (EVP_EncryptInit_ex(&ctx, kekciph, NULL, NULL, NULL) <= 0) {
|
||||||
|
@ -1230,15 +1230,18 @@ static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen,
|
|||||||
if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r,
|
if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r,
|
||||||
BN_num_bytes(dsa->q), s) == 0) {
|
BN_num_bytes(dsa->q), s) == 0) {
|
||||||
dsaret = DSA_SIG_new();
|
dsaret = DSA_SIG_new();
|
||||||
|
if (dsaret == NULL)
|
||||||
|
goto err;
|
||||||
dsaret->r = r;
|
dsaret->r = r;
|
||||||
dsaret->s = s;
|
dsaret->s = s;
|
||||||
|
r = s = NULL;
|
||||||
} else {
|
} else {
|
||||||
const DSA_METHOD *meth = DSA_OpenSSL();
|
const DSA_METHOD *meth = DSA_OpenSSL();
|
||||||
BN_free(r);
|
|
||||||
BN_free(s);
|
|
||||||
dsaret = (meth->dsa_do_sign) (dgst, dlen, dsa);
|
dsaret = (meth->dsa_do_sign) (dgst, dlen, dsa);
|
||||||
}
|
}
|
||||||
err:
|
err:
|
||||||
|
BN_free(r);
|
||||||
|
BN_free(s);
|
||||||
kop.crk_param[0].crp_p = NULL;
|
kop.crk_param[0].crp_p = NULL;
|
||||||
zapparams(&kop);
|
zapparams(&kop);
|
||||||
return (dsaret);
|
return (dsaret);
|
||||||
|
@ -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'))
|
if ((prompt == NULL) && (prompt_string[0] != '\0'))
|
||||||
prompt = prompt_string;
|
prompt = prompt_string;
|
||||||
ui = UI_new();
|
ui = UI_new();
|
||||||
|
if (ui == NULL)
|
||||||
|
return -1;
|
||||||
UI_add_input_string(ui, prompt, 0, buf, min,
|
UI_add_input_string(ui, prompt, 0, buf, min,
|
||||||
(len >= BUFSIZ) ? BUFSIZ - 1 : len);
|
(len >= BUFSIZ) ? BUFSIZ - 1 : len);
|
||||||
if (verify)
|
if (verify)
|
||||||
|
@ -218,6 +218,9 @@ static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg,
|
|||||||
BIGNUM *t3 = BN_new();
|
BIGNUM *t3 = BN_new();
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (h == NULL || t1 == NULL || t2 == NULL || t3 == NULL)
|
||||||
|
goto end;
|
||||||
|
|
||||||
zkp_hash(h, zkpg, p, ctx->p.peer_name);
|
zkp_hash(h, zkpg, p, ctx->p.peer_name);
|
||||||
|
|
||||||
/* t1 = g^b */
|
/* t1 = g^b */
|
||||||
@ -233,6 +236,7 @@ static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg,
|
|||||||
else
|
else
|
||||||
JPAKEerr(JPAKE_F_VERIFY_ZKP, JPAKE_R_ZKP_VERIFY_FAILED);
|
JPAKEerr(JPAKE_F_VERIFY_ZKP, JPAKE_R_ZKP_VERIFY_FAILED);
|
||||||
|
|
||||||
|
end:
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
BN_free(t3);
|
BN_free(t3);
|
||||||
BN_free(t2);
|
BN_free(t2);
|
||||||
|
@ -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->enc_len = 0;
|
||||||
|
|
||||||
xi->x_pkey = X509_PKEY_new();
|
xi->x_pkey = X509_PKEY_new();
|
||||||
|
if (xi->x_pkey == NULL)
|
||||||
|
goto err;
|
||||||
ptype = EVP_PKEY_RSA;
|
ptype = EVP_PKEY_RSA;
|
||||||
pp = &xi->x_pkey->dec_pkey;
|
pp = &xi->x_pkey->dec_pkey;
|
||||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
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->enc_len = 0;
|
||||||
|
|
||||||
xi->x_pkey = X509_PKEY_new();
|
xi->x_pkey = X509_PKEY_new();
|
||||||
|
if (xi->x_pkey == NULL)
|
||||||
|
goto err;
|
||||||
ptype = EVP_PKEY_DSA;
|
ptype = EVP_PKEY_DSA;
|
||||||
pp = &xi->x_pkey->dec_pkey;
|
pp = &xi->x_pkey->dec_pkey;
|
||||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
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->enc_len = 0;
|
||||||
|
|
||||||
xi->x_pkey = X509_PKEY_new();
|
xi->x_pkey = X509_PKEY_new();
|
||||||
|
if (xi->x_pkey == NULL)
|
||||||
|
goto err;
|
||||||
ptype = EVP_PKEY_EC;
|
ptype = EVP_PKEY_EC;
|
||||||
pp = &xi->x_pkey->dec_pkey;
|
pp = &xi->x_pkey->dec_pkey;
|
||||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
if ((int)strlen(header) > 10) /* assume encrypted */
|
||||||
|
@ -656,6 +656,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);
|
bio = BIO_new_mem_buf(data_body->data, data_body->length);
|
||||||
else {
|
else {
|
||||||
bio = BIO_new(BIO_s_mem());
|
bio = BIO_new(BIO_s_mem());
|
||||||
|
if (bio == NULL)
|
||||||
|
goto err;
|
||||||
BIO_set_mem_eof_return(bio, 0);
|
BIO_set_mem_eof_return(bio, 0);
|
||||||
}
|
}
|
||||||
if (bio == NULL)
|
if (bio == NULL)
|
||||||
|
@ -186,6 +186,10 @@ static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
pol = POLICYINFO_new();
|
pol = POLICYINFO_new();
|
||||||
|
if (pol == NULL) {
|
||||||
|
X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
pol->policyid = pobj;
|
pol->policyid = pobj;
|
||||||
}
|
}
|
||||||
if (!sk_POLICYINFO_push(pols, pol)) {
|
if (!sk_POLICYINFO_push(pols, pol)) {
|
||||||
|
@ -132,6 +132,8 @@ static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,
|
|||||||
}
|
}
|
||||||
tval.value = val->value;
|
tval.value = val->value;
|
||||||
sub = GENERAL_SUBTREE_new();
|
sub = GENERAL_SUBTREE_new();
|
||||||
|
if (sub == NULL)
|
||||||
|
goto memerr;
|
||||||
if (!v2i_GENERAL_NAME_ex(sub->base, method, ctx, &tval, 1))
|
if (!v2i_GENERAL_NAME_ex(sub->base, method, ctx, &tval, 1))
|
||||||
goto err;
|
goto err;
|
||||||
if (!*ptree)
|
if (!*ptree)
|
||||||
|
@ -839,6 +839,10 @@ static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
|
|||||||
bn_fix_top(rtmp->n);
|
bn_fix_top(rtmp->n);
|
||||||
|
|
||||||
res = EVP_PKEY_new();
|
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);
|
EVP_PKEY_assign_RSA(res, rtmp);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
@ -2825,6 +2825,11 @@ int ssl3_send_client_key_exchange(SSL *s)
|
|||||||
|
|
||||||
pkey_ctx = EVP_PKEY_CTX_new(pub_key =
|
pkey_ctx = EVP_PKEY_CTX_new(pub_key =
|
||||||
X509_get_pubkey(peer_cert), NULL);
|
X509_get_pubkey(peer_cert), NULL);
|
||||||
|
if (pkey_ctx == NULL) {
|
||||||
|
SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
|
||||||
|
ERR_R_MALLOC_FAILURE);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* If we have send a certificate, and certificate key
|
* If we have send a certificate, and certificate key
|
||||||
*
|
*
|
||||||
|
@ -2878,6 +2878,11 @@ int ssl3_get_client_key_exchange(SSL *s)
|
|||||||
pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey;
|
pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey;
|
||||||
|
|
||||||
pkey_ctx = EVP_PKEY_CTX_new(pk, NULL);
|
pkey_ctx = EVP_PKEY_CTX_new(pk, NULL);
|
||||||
|
if (pkey_ctx == NULL) {
|
||||||
|
al = SSL_AD_INTERNAL_ERROR;
|
||||||
|
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);
|
||||||
|
goto f_err;
|
||||||
|
}
|
||||||
EVP_PKEY_decrypt_init(pkey_ctx);
|
EVP_PKEY_decrypt_init(pkey_ctx);
|
||||||
/*
|
/*
|
||||||
* If client certificate is present and is of the same type, maybe
|
* If client certificate is present and is of the same type, maybe
|
||||||
@ -3122,6 +3127,11 @@ int ssl3_get_cert_verify(SSL *s)
|
|||||||
unsigned char signature[64];
|
unsigned char signature[64];
|
||||||
int idx;
|
int idx;
|
||||||
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(pkey, NULL);
|
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(pkey, NULL);
|
||||||
|
if (pctx == NULL) {
|
||||||
|
al = SSL_AD_INTERNAL_ERROR;
|
||||||
|
SSLerr(SSL_F_SSL3_GET_CERT_VERIFY, ERR_R_MALLOC_FAILURE);
|
||||||
|
goto f_err;
|
||||||
|
}
|
||||||
EVP_PKEY_verify_init(pctx);
|
EVP_PKEY_verify_init(pctx);
|
||||||
if (i != 64) {
|
if (i != 64) {
|
||||||
fprintf(stderr, "GOST signature length is %d", i);
|
fprintf(stderr, "GOST signature length is %d", i);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user