From 2660580507a96545cd261fa1defe903488e04368 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 15 Jan 2022 22:49:56 -0500 Subject: [PATCH] lib/otp: opt_md_init do not leak ctx if malloc fails Change-Id: I21d7d50e11430bea18832854d817405b761c254c --- lib/otp/otp_md.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/otp/otp_md.c b/lib/otp/otp_md.c index 1d6fe9594..9338a204d 100644 --- a/lib/otp/otp_md.c +++ b/lib/otp/otp_md.c @@ -92,8 +92,6 @@ otp_md_init (OtpKey key, char *p; int len; - ctx = EVP_MD_CTX_create(); - len = strlen(pwd) + strlen(seed); p = malloc (len + 1); if (p == NULL) @@ -102,6 +100,8 @@ otp_md_init (OtpKey key, strlwr (p); strlcat (p, pwd, len + 1); + ctx = EVP_MD_CTX_create(); + EVP_DigestInit_ex(ctx, md, NULL); EVP_DigestUpdate(ctx, p, len); EVP_DigestFinal_ex(ctx, res, NULL);