From 78d1f70ab6e631cc386b0f45c3e5bd151bf5b3fd Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 5 Apr 2019 09:56:10 +0100 Subject: [PATCH] Ensure non-NULL key buffer when building SSL test transforms --- tests/suites/test_suite_ssl.function | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function index d8f022ff4..05ecd8ad5 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -41,8 +41,11 @@ static int build_transforms( mbedtls_ssl_transform *t_in, /* Pick keys */ keylen = cipher_info->key_bitlen / 8; - CHK( ( key0 = mbedtls_calloc( 1, keylen ) ) != NULL ); - CHK( ( key1 = mbedtls_calloc( 1, keylen ) ) != NULL ); + /* Allocate `keylen + 1` bytes to ensure that we get + * a non-NULL pointers from `mbedtls_calloc` even if + * `keylen == 0` in the case of the NULL cipher. */ + CHK( ( key0 = mbedtls_calloc( 1, keylen + 1 ) ) != NULL ); + CHK( ( key1 = mbedtls_calloc( 1, keylen + 1 ) ) != NULL ); memset( key0, 0x1, keylen ); memset( key1, 0x2, keylen );