Make sure no random pointer occur during failed malloc()'s

This commit is contained in:
Paul Bakker 2014-03-26 15:28:55 +01:00
parent db1f05985e
commit 77f4f39ea6
2 changed files with 11 additions and 4 deletions

View file

@ -56,6 +56,8 @@ Bugfix
containing a client certificate
* ssl_init() was leaving a dirty pointer in ssl_context if malloc of
out_ctr failed
* ssl_handshake_init() was leaving dirty pointers in subcontexts if malloc
of one of them failed
* Fix typo in rsa_copy() that impacted PKCS#1 v2 contexts
= PolarSSL 1.3.4 released on 2014-01-27

View file

@ -3318,6 +3318,9 @@ static int ssl_handshake_init( ssl_context *ssl )
{
ssl->transform_negotiate =
(ssl_transform *) polarssl_malloc( sizeof(ssl_transform) );
if( ssl->transform_negotiate != NULL )
memset( ssl->transform_negotiate, 0, sizeof(ssl_transform) );
}
if( ssl->session_negotiate )
@ -3326,6 +3329,9 @@ static int ssl_handshake_init( ssl_context *ssl )
{
ssl->session_negotiate =
(ssl_session *) polarssl_malloc( sizeof(ssl_session) );
if( ssl->session_negotiate != NULL )
memset( ssl->session_negotiate, 0, sizeof(ssl_session) );
}
if( ssl->handshake )
@ -3334,6 +3340,9 @@ static int ssl_handshake_init( ssl_context *ssl )
{
ssl->handshake = (ssl_handshake_params *)
polarssl_malloc( sizeof(ssl_handshake_params) );
if( ssl->handshake != NULL )
memset( ssl->handshake, 0, sizeof(ssl_handshake_params) );
}
if( ssl->handshake == NULL ||
@ -3344,10 +3353,6 @@ static int ssl_handshake_init( ssl_context *ssl )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
}
memset( ssl->handshake, 0, sizeof(ssl_handshake_params) );
memset( ssl->transform_negotiate, 0, sizeof(ssl_transform) );
memset( ssl->session_negotiate, 0, sizeof(ssl_session) );
#if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
defined(POLARSSL_SSL_PROTO_TLS1_1)
md5_starts( &ssl->handshake->fin_md5 );