From a23eafce3ae5ac76ffd708afc06ee2e20946d51f Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 3 Dec 2018 16:48:14 +0100 Subject: [PATCH] Fix snprintf call to assume less about integral type sizes The code only worked if psa_key_id_t (formerly psa_key_slot_t) promoted to int and every value fit in int. Now the code only assumes that psa_key_id_t is less wide than unsigned long, which is the case since psa_key_id_t is a 32-bit type in our implementation. --- library/psa_crypto_storage_file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/psa_crypto_storage_file.c b/library/psa_crypto_storage_file.c index 95857fa406..87420be98a 100644 --- a/library/psa_crypto_storage_file.c +++ b/library/psa_crypto_storage_file.c @@ -53,7 +53,8 @@ static void key_id_to_location( const psa_key_id_t key, size_t location_size ) { mbedtls_snprintf( location, location_size, - CRYPTO_STORAGE_FILE_LOCATION "psa_key_slot_%d", key ); + CRYPTO_STORAGE_FILE_LOCATION "psa_key_slot_%lu", + (unsigned long) key ); } psa_status_t psa_crypto_storage_load( const psa_key_id_t key, uint8_t *data,