lib/otp: opt_md_init do not leak ctx if malloc fails

Change-Id: I21d7d50e11430bea18832854d817405b761c254c
This commit is contained in:
Jeffrey Altman
2022-01-15 22:49:56 -05:00
parent fe76d53316
commit 2660580507

View File

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