From e7ed8c4c2f7448ea00d67679354e7303830c9434 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 5 Jun 2025 16:00:27 +0200 Subject: [PATCH] Explain some aspects of the tests Signed-off-by: Gilles Peskine --- tests/suites/test_suite_base64.data | 3 +++ tests/suites/test_suite_base64.function | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/tests/suites/test_suite_base64.data b/tests/suites/test_suite_base64.data index 547b9fd127..feed172d9c 100644 --- a/tests/suites/test_suite_base64.data +++ b/tests/suites/test_suite_base64.data @@ -78,6 +78,8 @@ mbedtls_base64_decode:"zm masd":"":MBEDTLS_ERR_BASE64_INVALID_CHARACTER # The next few test cases validate systematically for short inputs that # we require the correct number of trailing equal signs. + +# 4k+1 digits is always wrong (wouldn't encode more bytes than 4k digits) Base64 decode: 1 digit, 0 equals (bad) mbedtls_base64_decode:"Y":"":MBEDTLS_ERR_BASE64_INVALID_CHARACTER @@ -126,6 +128,7 @@ mbedtls_base64_decode:"Y29t==":"com":MBEDTLS_ERR_BASE64_INVALID_CHARACTER Base64 decode: 4 digits, 3 equals (bad) mbedtls_base64_decode:"Y29t===":"com":MBEDTLS_ERR_BASE64_INVALID_CHARACTER +# 4k+1 digits is always wrong (wouldn't encode more bytes than 4k digits) Base64 decode: 5 digits, 0 equals (bad) mbedtls_base64_decode:"Y29tc":"":MBEDTLS_ERR_BASE64_INVALID_CHARACTER diff --git a/tests/suites/test_suite_base64.function b/tests/suites/test_suite_base64.function index 8c948b4b57..df63aea06f 100644 --- a/tests/suites/test_suite_base64.function +++ b/tests/suites/test_suite_base64.function @@ -92,11 +92,16 @@ void mbedtls_base64_decode(char *src_string, char *dst_string, int result) size_t dst_size = correct_dst_len; size_t len; + /* Allocate exactly the size of the input, to ensure there's no buffer + * overread in builds with ASan. (src_string has at least one extra null + * character at the end.) */ TEST_CALLOC(src, src_len); if (src_len != 0) { memcpy(src, src_string, src_len); } + /* Allocate exactly the size of the input, to ensure there's no buffer + * overflow in builds with ASan. */ TEST_CALLOC(dst, dst_size); /* Test normal operation */