From 910c76b3d101a47fd39dbdadcbc1cabf37ed36de Mon Sep 17 00:00:00 2001 From: itayzafrir Date: Wed, 21 Nov 2018 16:03:21 +0200 Subject: [PATCH] Check that memory allocation was successful in psa_save_generated_persistent_key --- library/psa_crypto.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 58cb73830..05b8a8e8b 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1117,6 +1117,8 @@ static psa_status_t psa_save_generated_persistent_key( psa_key_slot_t key, size_t key_length; size_t data_size = PSA_KEY_EXPORT_MAX_SIZE( slot->type, bits ); data = mbedtls_calloc( 1, data_size ); + if( data == NULL ) + return( PSA_ERROR_INSUFFICIENT_MEMORY ); /* Get key data in export format */ status = psa_internal_export_key( slot, data, data_size, &key_length, 0 ); if( status != PSA_SUCCESS )