From 1bc6caceb1420bf1c02833d3919985c11aba020b Mon Sep 17 00:00:00 2001 From: lixiaokeng Date: Mon, 9 Nov 2020 09:52:32 +0800 Subject: [PATCH] lib: fix memory leak in crypt_pbkdf_check There is a memory leak when PBKDF2_temp > UINT32_MAX. Here, we change return to goto out to free key. Signed-off-by: Lixiaokeng Signed-off-by: Linfeilong --- lib/crypto_backend/pbkdf_check.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/crypto_backend/pbkdf_check.c b/lib/crypto_backend/pbkdf_check.c index 7444e0aa..2c86036c 100644 --- a/lib/crypto_backend/pbkdf_check.c +++ b/lib/crypto_backend/pbkdf_check.c @@ -361,8 +361,10 @@ static int crypt_pbkdf_check(const char *kdf, const char *hash, ms = time_ms(&rstart, &rend); if (ms) { PBKDF2_temp = (double)iterations * target_ms / ms; - if (PBKDF2_temp > UINT32_MAX) - return -EINVAL; + if (PBKDF2_temp > UINT32_MAX) { + r = -EINVAL; + goto out; + } *iter_secs = (uint32_t)PBKDF2_temp; }