Re-use buffer allocated by handshake_init()

This fixes a memory leak as well (found by running ssl-opt.sh in an Asan
build).
This commit is contained in:
Manuel Pégourié-Gonnard 2019-07-23 14:43:30 +02:00
parent 0d83271a45
commit ff22200fab

View File

@ -11048,13 +11048,12 @@ static int ssl_context_load( mbedtls_ssl_context *ssl,
( (size_t) p[3] );
p += 4;
ssl->session = mbedtls_calloc( 1, sizeof( mbedtls_ssl_session ) );
if( ssl->session == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
mbedtls_ssl_session_init( ssl->session );
/* This has been allocated by ssl_handshake_init(), called by
* by either ssl_session_reset_int() or mbedtls_ssl_setup(). */
ssl->session = ssl->session_negotiate;
ssl->session_in = ssl->session;
ssl->session_out = ssl->session;
ssl->session_negotiate = NULL;
if( (size_t)( end - p ) < session_len )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
@ -11069,14 +11068,12 @@ static int ssl_context_load( mbedtls_ssl_context *ssl,
* Transform
*/
/* Allocate and initialize structure */
ssl->transform = mbedtls_calloc( 1, sizeof( mbedtls_ssl_transform ) );
if( ssl->transform == NULL )
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
mbedtls_ssl_transform_init( ssl->transform );
/* This has been allocated by ssl_handshake_init(), called by
* by either ssl_session_reset_int() or mbedtls_ssl_setup(). */
ssl->transform = ssl->transform_negotiate;
ssl->transform_in = ssl->transform;
ssl->transform_out = ssl->transform;
ssl->transform_negotiate = NULL;
/* Read random bytes and populate structure */
if( (size_t)( end - p ) < sizeof( ssl->transform->randbytes ) )