- Set sane start values for structures that are closed or freed.

This commit is contained in:
Paul Bakker 2011-02-06 13:22:40 +00:00
parent 896b3be1d1
commit 1a207ec8af
3 changed files with 24 additions and 9 deletions

View file

@ -62,6 +62,7 @@ int main( void )
*/
havege_init( &hs );
memset( &ssn, 0, sizeof( ssl_session ) );
memset( &ssl, 0, sizeof( ssl_context ) );
/*
* 1. Start the connection

View file

@ -92,6 +92,16 @@ int main( int argc, char *argv[] )
int i, j, n;
char *p, *q;
/*
* Make sure memory references are valid.
*/
server_fd = 0;
memset( &ssn, 0, sizeof( ssl_session ) );
memset( &ssl, 0, sizeof( ssl_context ) );
memset( &cacert, 0, sizeof( x509_cert ) );
memset( &clicert, 0, sizeof( x509_cert ) );
memset( &rsa, 0, sizeof( rsa_context ) );
if( argc == 0 )
{
usage:
@ -149,7 +159,6 @@ int main( int argc, char *argv[] )
* 0. Initialize the RNG and the session data
*/
havege_init( &hs );
memset( &ssn, 0, sizeof( ssl_session ) );
/*
* 1.1. Load the trusted CA
@ -157,8 +166,6 @@ int main( int argc, char *argv[] )
printf( "\n . Loading the CA root certificate ..." );
fflush( stdout );
memset( &cacert, 0, sizeof( x509_cert ) );
/*
* Alternatively, you may load the CA certificates from a .pem or
* .crt file by calling x509parse_crtfile( &cacert, "myca.crt" ).
@ -181,8 +188,6 @@ int main( int argc, char *argv[] )
printf( " . Loading the client cert. and key..." );
fflush( stdout );
memset( &clicert, 0, sizeof( x509_cert ) );
if( strlen( opt.crt_file ) )
ret = x509parse_crtfile( &clicert, opt.crt_file );
else
@ -357,7 +362,8 @@ int main( int argc, char *argv[] )
exit:
net_close( server_fd );
if( server_fd )
net_close( server_fd );
x509_free( &clicert );
x509_free( &cacert );
rsa_free( &rsa );

View file

@ -89,6 +89,15 @@ int main( int argc, char *argv[] )
int i, j, n;
char *p, *q;
/*
* Set to sane values
*/
server_fd = 0;
memset( &ssl, 0, sizeof( ssl_context ) );
memset( &ssn, 0, sizeof( ssl_session ) );
memset( &clicert, 0, sizeof( x509_cert ) );
memset( &rsa, 0, sizeof( rsa_context ) );
if( argc == 0 )
{
usage:
@ -149,7 +158,6 @@ int main( int argc, char *argv[] )
if( opt.mode == MODE_FILE )
{
x509_cert crt;
memset( &crt, 0, sizeof( x509_cert ) );
/*
@ -191,7 +199,6 @@ int main( int argc, char *argv[] )
* 1. Initialize the RNG and the session data
*/
havege_init( &hs );
memset( &ssn, 0, sizeof( ssl_session ) );
/*
* 2. Start the connection
@ -265,7 +272,8 @@ int main( int argc, char *argv[] )
exit:
net_close( server_fd );
if( server_fd )
net_close( server_fd );
x509_free( &clicert );
rsa_free( &rsa );
ssl_free( &ssl );