From b9fbc11e2c60a7c0f748c60ffc7e96e7a6665457 Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Fri, 14 Jan 2022 16:31:39 +0100 Subject: [PATCH] Dynamically allocate iv in dec_empty_buf tests Signed-off-by: Andrzej Kurek --- tests/suites/test_suite_cipher.function | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function index 2aa7303ac..cd79ba47f 100644 --- a/tests/suites/test_suite_cipher.function +++ b/tests/suites/test_suite_cipher.function @@ -571,8 +571,9 @@ void dec_empty_buf( int cipher, int expected_finish_ret ) { unsigned char key[32]; - unsigned char iv[16]; - size_t iv_len = sizeof(iv); + + unsigned char *iv = NULL; + size_t iv_len = 16; mbedtls_cipher_context_t ctx_dec; const mbedtls_cipher_info_t *cipher_info; @@ -583,7 +584,6 @@ void dec_empty_buf( int cipher, size_t outlen = 0; memset( key, 0, 32 ); - memset( iv , 0, 16 ); mbedtls_cipher_init( &ctx_dec ); @@ -598,6 +598,9 @@ void dec_empty_buf( int cipher, cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 ) iv_len = 12; + ASSERT_ALLOC( iv, iv_len ); + memset( iv , 0, iv_len ); + TEST_ASSERT( sizeof(key) * 8 >= cipher_info->key_bitlen ); TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) ); @@ -636,6 +639,7 @@ void dec_empty_buf( int cipher, TEST_ASSERT( 0 == outlen ); exit: + mbedtls_free( iv ); mbedtls_cipher_free( &ctx_dec ); } /* END_CASE */