Explain some aspects of the tests

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2025-06-05 16:00:27 +02:00
parent 2b3d6a8f28
commit e7ed8c4c2f
2 changed files with 8 additions and 0 deletions

View File

@@ -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

View File

@@ -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 */