From ab9dc667ffc6e1e2bc10a131487da6f926ac9afe Mon Sep 17 00:00:00 2001 From: Valerio Setti Date: Mon, 27 Mar 2023 14:02:08 +0200 Subject: [PATCH] psa_util: fix for correctly computing elements in array Signed-off-by: Valerio Setti --- include/mbedtls/psa_util.h | 6 ++++-- library/psa_util.c | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/mbedtls/psa_util.h b/include/mbedtls/psa_util.h index 6d5843d01..b750716a9 100644 --- a/include/mbedtls/psa_util.h +++ b/include/mbedtls/psa_util.h @@ -388,8 +388,10 @@ int psa_status_to_mbedtls(psa_status_t status, int psa_pk_status_to_mbedtls(psa_status_t status); /* Utility macro to shorten the defines of error translator in modules. */ -#define PSA_TO_MBEDTLS_ERR_LIST(status, error_list, fallback_f) \ - psa_status_to_mbedtls(status, error_list, sizeof(error_list), fallback_f) +#define PSA_TO_MBEDTLS_ERR_LIST(status, error_list, fallback_f) \ + psa_status_to_mbedtls(status, error_list, \ + sizeof(error_list)/sizeof(error_list[0]), \ + fallback_f) #endif /* MBEDTLS_PSA_CRYPTO_C */ #endif /* MBEDTLS_PSA_UTIL_H */ diff --git a/library/psa_util.c b/library/psa_util.c index fefeea56d..43a10a32c 100644 --- a/library/psa_util.c +++ b/library/psa_util.c @@ -112,10 +112,9 @@ int psa_generic_status_to_mbedtls(psa_status_t status) int psa_status_to_mbedtls(psa_status_t status, const mbedtls_error_pair_t *local_translations, - size_t local_errors_size, + size_t local_errors_num, int (*fallback_f)(psa_status_t)) { - size_t local_errors_num = (size_t) local_errors_size / 2; for (size_t i = 0; i < local_errors_num; i++) { if (status == local_translations[i].psa_status) { return local_translations[i].mbedtls_error;