From 0892d0fbbf5778d40d9cd1c81ba841d86e19c5c4 Mon Sep 17 00:00:00 2001 From: Darryl Green Date: Tue, 20 Aug 2019 09:50:14 +0100 Subject: [PATCH] Initialize key bits to max size + 1 in psa_import_key In psa_import_key, the key bits value was uninitialized before calling the secure element driver import function. There is a potential issue if the driver returns PSA_SUCCESS without setting the key bits. This shouldn't happen, but shouldn't be discounted either, so we initialize the key bits to an invalid issue. --- library/psa_crypto.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 6ec2a1c383..93af0d398c 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1835,7 +1835,9 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes, if( driver != NULL ) { const psa_drv_se_t *drv = psa_get_se_driver_methods( driver ); - size_t bits; + /* The driver should set the number of key bits, however in + * case it doesn't, we initialize bits to an invalid value. */ + size_t bits = PSA_MAX_KEY_BITS + 1; if( drv->key_management == NULL || drv->key_management->p_import == NULL ) {