From 28b3b29306fe9816041267628cb4e23d25b279a3 Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Thu, 22 Oct 2020 11:40:41 +0200 Subject: [PATCH] ssl_tls.c: Fix unchecked memory allocation Signed-off-by: Andrzej Kurek --- library/ssl_tls.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 8a014ced3..40b6f70c7 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -1662,6 +1662,11 @@ int ssl_populate_transform( mbedtls_ssl_transform *transform, transform->key_enc = mbedtls_calloc( 1, cipher_info->key_bitlen >> 3 ); transform->key_dec = mbedtls_calloc( 1, cipher_info->key_bitlen >> 3 ); + if( transform->key_enc == NULL || transform->key_dec == NULL ) + { + MBEDTLS_SSL_DEBUG_MSG( 1, ( "Failed to allocate cipher keys" ) ); + return( MBEDTLS_ERR_SSL_INTERNAL_ERROR ); + } memcpy( transform->key_enc, key1, cipher_info->key_bitlen >> 3 ); memcpy( transform->key_dec, key2, cipher_info->key_bitlen >> 3 );