From dd9e8f6dd065bb21928674d94c075ab14a57f2ca Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 9 Dec 2020 14:53:24 +0000 Subject: [PATCH] Fix potential buffer overflow in printf Printf could potentially produce 2 64 bit numbers here when there is only space for one, thus causing a buffer overflow. This was caught by the new warning flags. Signed-off-by: Paul Elliott --- library/psa_its_file.c | 1 + tests/suites/test_suite_psa_its.function | 1 + 2 files changed, 2 insertions(+) diff --git a/library/psa_its_file.c b/library/psa_its_file.c index 2fbff20ef..8dff7834d 100644 --- a/library/psa_its_file.c +++ b/library/psa_its_file.c @@ -51,6 +51,7 @@ #define PSA_ITS_STORAGE_SUFFIX ".psa_its" #define PSA_ITS_STORAGE_FILENAME_LENGTH \ ( sizeof( PSA_ITS_STORAGE_PREFIX ) - 1 + /*prefix without terminating 0*/ \ + 16 + /*UID (64-bit number in hex)*/ \ 16 + /*UID (64-bit number in hex)*/ \ sizeof( PSA_ITS_STORAGE_SUFFIX ) - 1 + /*suffix without terminating 0*/ \ 1 /*terminating null byte*/ ) diff --git a/tests/suites/test_suite_psa_its.function b/tests/suites/test_suite_psa_its.function index 330846a02..fb9ce0703 100644 --- a/tests/suites/test_suite_psa_its.function +++ b/tests/suites/test_suite_psa_its.function @@ -16,6 +16,7 @@ #define PSA_ITS_STORAGE_SUFFIX ".psa_its" #define PSA_ITS_STORAGE_FILENAME_LENGTH \ ( sizeof( PSA_ITS_STORAGE_PREFIX ) - 1 + /*prefix without terminating 0*/ \ + 16 + /*UID (64-bit number in hex)*/ \ 16 + /*UID (64-bit number in hex)*/ \ sizeof( PSA_ITS_STORAGE_SUFFIX ) - 1 + /*suffix without terminating 0*/ \ 1 /*terminating null byte*/ )