summaryrefslogtreecommitdiffstats
path: root/crypto/evp
diff options
context:
space:
mode:
authorkinichiro <kinichiro.inoguchi@gmail.com>2020-01-12 17:35:39 +0900
committerDr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>2020-02-06 17:21:31 +0100
commit6527714c25a4266504e323395fd9ffd1bccb2041 (patch)
tree82c77f26a0e05d0a731b3f9efa1246bff80aafa2 /crypto/evp
parent3948408f2a6370556d833dc4947ffaaca82ebb78 (diff)
Avoid leak in error path of PKCS5_PBE_keyivgen
CLA: trivial Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/10816) (cherry picked from commit adc9086beb21a91ca59aaf0c619b38b82c223f9b)
Diffstat (limited to 'crypto/evp')
-rw-r--r--crypto/evp/p5_crpt.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/crypto/evp/p5_crpt.c b/crypto/evp/p5_crpt.c
index 4747714366..95e2d9c5dc 100644
--- a/crypto/evp/p5_crpt.c
+++ b/crypto/evp/p5_crpt.c
@@ -51,11 +51,13 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
ivl = EVP_CIPHER_iv_length(cipher);
if (ivl < 0 || ivl > 16) {
EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, EVP_R_INVALID_IV_LENGTH);
+ PBEPARAM_free(pbe);
return 0;
}
kl = EVP_CIPHER_key_length(cipher);
if (kl < 0 || kl > (int)sizeof(md_tmp)) {
EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, EVP_R_INVALID_KEY_LENGTH);
+ PBEPARAM_free(pbe);
return 0;
}
@@ -84,6 +86,7 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
if (!EVP_DigestUpdate(ctx, salt, saltlen))
goto err;
PBEPARAM_free(pbe);
+ pbe = NULL;
if (!EVP_DigestFinal_ex(ctx, md_tmp, NULL))
goto err;
mdsize = EVP_MD_size(md);
@@ -106,6 +109,7 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH);
rv = 1;
err:
+ PBEPARAM_free(pbe);
EVP_MD_CTX_free(ctx);
return rv;
}