From 1ae051409f69d0db7c492fa59b57bc8755c71109 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Sat, 30 Jun 2018 17:46:59 +0200 Subject: [PATCH] Fix memory leak when importing an RSA key that is too large --- library/psa_crypto.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 19db5a9ec..1d5337bfb 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -514,7 +514,10 @@ psa_status_t psa_import_key( psa_key_slot_t key, mbedtls_rsa_context *rsa = mbedtls_pk_rsa( pk ); size_t bits = mbedtls_rsa_get_bitlen( rsa ); if( bits > PSA_VENDOR_RSA_MAX_KEY_BITS ) - return( PSA_ERROR_NOT_SUPPORTED ); + { + status = PSA_ERROR_NOT_SUPPORTED; + break; + } slot->data.rsa = rsa; } else