Merge pull request #3815 from AndrzejKurek/cipher-optim-mem-fix

ssl_tls.c: Fix unchecked memory allocation
This commit is contained in:
Andrzej Kurek 2020-11-02 11:41:24 +01:00 committed by GitHub
commit 8b0910a791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1728,6 +1728,11 @@ int ssl_populate_transform( mbedtls_ssl_transform *transform,
transform->key_enc = mbedtls_calloc( 1, cipher_info->key_bitlen >> 3 ); transform->key_enc = mbedtls_calloc( 1, cipher_info->key_bitlen >> 3 );
transform->key_dec = 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_enc, key1, cipher_info->key_bitlen >> 3 );
memcpy( transform->key_dec, key2, cipher_info->key_bitlen >> 3 ); memcpy( transform->key_dec, key2, cipher_info->key_bitlen >> 3 );