From: Alessandro Ghedini Date: Thu, 8 Oct 2015 12:50:27 +0000 (+0200) Subject: Check memory allocation X-Git-Tag: OpenSSL_1_1_0-pre1~388 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cf9d71a3a43d9b98a8a278d47dc08088a954a7b;p=openssl Check memory allocation Reviewed-by: Rich Salz Reviewed-by: Richard Levitte --- diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c index fb7947e322..e5b1739486 100644 --- a/crypto/evp/evp_pbe.c +++ b/crypto/evp/evp_pbe.c @@ -209,12 +209,15 @@ int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, { EVP_PBE_CTL *pbe_tmp; - if (pbe_algs == NULL) + if (pbe_algs == NULL) { pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp); - if ((pbe_tmp = OPENSSL_malloc(sizeof(*pbe_tmp))) == NULL) { - EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE, ERR_R_MALLOC_FAILURE); - return 0; + if (pbe_algs == NULL) + goto err; } + + if ((pbe_tmp = OPENSSL_malloc(sizeof(*pbe_tmp))) == NULL) + goto err; + pbe_tmp->pbe_type = pbe_type; pbe_tmp->pbe_nid = pbe_nid; pbe_tmp->cipher_nid = cipher_nid; @@ -223,6 +226,10 @@ int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, sk_EVP_PBE_CTL_push(pbe_algs, pbe_tmp); return 1; + + err: + EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE, ERR_R_MALLOC_FAILURE); + return 0; } int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,