aboutsummaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorRyan Everett <ryan.everett@arm.com>2024-04-29 18:24:58 +0100
committerRyan Everett <ryan.everett@arm.com>2024-04-29 18:24:58 +0100
commitdd90507dc679284d1c99f3e18bafeb51e539e221 (patch)
treec934f75a71d0c6ec77c007553d59aa6936e8279f /library
parent024d3daa7d367e58aaab6a5b06e42aa440e3fa37 (diff)
downloadmbedtls-dd90507dc679284d1c99f3e18bafeb51e539e221.zip
mbedtls-dd90507dc679284d1c99f3e18bafeb51e539e221.tar.gz
mbedtls-dd90507dc679284d1c99f3e18bafeb51e539e221.tar.bz2
Fix potential non-NULL slot return on failure
If psa_get_and_lock_key_slot fails, the slot must be wiped. This fixes a bug where a pointer to some valid key slot can be incorrectly returned Signed-off-by: Ryan Everett <ryan.everett@arm.com>
Diffstat (limited to 'library')
-rw-r--r--library/psa_crypto_slot_management.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c
index b184ed0..fbcb26e 100644
--- a/library/psa_crypto_slot_management.c
+++ b/library/psa_crypto_slot_management.c
@@ -440,6 +440,9 @@ psa_status_t psa_get_and_lock_key_slot(mbedtls_svc_key_id_t key,
status = PSA_ERROR_INVALID_HANDLE;
#endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C || MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
+ if (status != PSA_SUCCESS) {
+ *p_slot = NULL;
+ }
#if defined(MBEDTLS_THREADING_C)
PSA_THREADING_CHK_RET(mbedtls_mutex_unlock(
&mbedtls_threading_key_slot_mutex));