mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-10-30 19:07:48 +08:00
Use a null pointer for empty data
Don't allocate an extra byte when a binary input is empty. This could hide bugs where the library tries to access one byte in an empty buffer. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
01b5d6a5be
commit
31d6a8a22c
@ -306,7 +306,7 @@ void aes_encrypt_xts(char *hex_key_string, char *hex_data_unit_string,
|
||||
dst = mbedtls_test_unhexify_alloc(hex_dst_string, &dst_len);
|
||||
TEST_ASSERT(src_len == dst_len);
|
||||
|
||||
output = mbedtls_test_zero_alloc(dst_len);
|
||||
TEST_CALLOC(output, dst_len);
|
||||
|
||||
TEST_ASSERT(mbedtls_aes_xts_setkey_enc(&ctx, key, key_len * 8) == 0);
|
||||
TEST_ASSERT(mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_ENCRYPT, src_len,
|
||||
@ -350,7 +350,7 @@ void aes_decrypt_xts(char *hex_key_string, char *hex_data_unit_string,
|
||||
dst = mbedtls_test_unhexify_alloc(hex_dst_string, &dst_len);
|
||||
TEST_ASSERT(src_len == dst_len);
|
||||
|
||||
output = mbedtls_test_zero_alloc(dst_len);
|
||||
TEST_CALLOC(output, dst_len);
|
||||
|
||||
TEST_ASSERT(mbedtls_aes_xts_setkey_dec(&ctx, key, key_len * 8) == 0);
|
||||
TEST_ASSERT(mbedtls_aes_crypt_xts(&ctx, MBEDTLS_AES_DECRYPT, src_len,
|
||||
|
||||
@ -109,7 +109,7 @@ void base64_encode_hex(data_t *src, char *dst, int dst_buf_size,
|
||||
unsigned char *res = NULL;
|
||||
size_t len;
|
||||
|
||||
res = mbedtls_test_zero_alloc(dst_buf_size);
|
||||
TEST_CALLOC(res, dst_buf_size);
|
||||
|
||||
TEST_CF_SECRET(src->x, src->len);
|
||||
TEST_ASSERT(mbedtls_base64_encode(res, dst_buf_size, &len, src->x, src->len) == result);
|
||||
@ -136,7 +136,7 @@ void base64_decode_hex(char *src, data_t *dst, int dst_buf_size,
|
||||
unsigned char *res = NULL;
|
||||
size_t len;
|
||||
|
||||
res = mbedtls_test_zero_alloc(dst_buf_size);
|
||||
TEST_CALLOC(res, dst_buf_size);
|
||||
|
||||
TEST_ASSERT(mbedtls_base64_decode(res, dst_buf_size, &len, (unsigned char *) src,
|
||||
strlen(src)) == result);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user