From da3e7db4956d4af8807e8f6de0db3d3a33a33ba7 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 9 Feb 2021 18:58:20 +0000 Subject: [PATCH 1/2] Fix memory leak in error case in psa_crypto In psa_generate_derived_key_internal() an error case was returning directly rather than jumping to the exit label, which meant that an allocated buffer would not be free'd. Found via coverity. Signed-off-by: Paul Elliott --- ChangeLog.d/fix_psa_crypto_leak.txt | 2 ++ library/psa_crypto.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 ChangeLog.d/fix_psa_crypto_leak.txt diff --git a/ChangeLog.d/fix_psa_crypto_leak.txt b/ChangeLog.d/fix_psa_crypto_leak.txt new file mode 100644 index 000000000..5add73dbd --- /dev/null +++ b/ChangeLog.d/fix_psa_crypto_leak.txt @@ -0,0 +1,2 @@ +Bugfix + * Fix memory leak that occured in error case in psa_generate_derived_key_internal() diff --git a/library/psa_crypto.c b/library/psa_crypto.c index c00875bd0..0855b02ac 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -5147,7 +5147,7 @@ static psa_status_t psa_generate_derived_key_internal( status = psa_allocate_buffer_to_slot( slot, bytes ); if( status != PSA_SUCCESS ) - return( status ); + goto exit; slot->attr.bits = (psa_key_bits_t) bits; psa_key_attributes_t attributes = { From d17062e6bfb0005cd4147684f1ed10a43d2008a5 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 12 Feb 2021 14:47:31 +0000 Subject: [PATCH 2/2] Correct english in changelog. Signed-off-by: Paul Elliott --- ChangeLog.d/fix_psa_crypto_leak.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.d/fix_psa_crypto_leak.txt b/ChangeLog.d/fix_psa_crypto_leak.txt index 5add73dbd..6f9e5feb3 100644 --- a/ChangeLog.d/fix_psa_crypto_leak.txt +++ b/ChangeLog.d/fix_psa_crypto_leak.txt @@ -1,2 +1,2 @@ Bugfix - * Fix memory leak that occured in error case in psa_generate_derived_key_internal() + * Fix a memory leak in an error case in psa_generate_derived_key_internal().