From 1a207ec8afb621fd90ecec59f8014e6088781433 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Sun, 6 Feb 2011 13:22:40 +0000 Subject: [PATCH] - Set sane start values for structures that are closed or freed. --- programs/ssl/ssl_client1.c | 1 + programs/ssl/ssl_client2.c | 18 ++++++++++++------ programs/x509/cert_app.c | 14 +++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c index ac02aeb5a..1c75bc5d8 100644 --- a/programs/ssl/ssl_client1.c +++ b/programs/ssl/ssl_client1.c @@ -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 diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index c27aeb8c2..7321fa55f 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -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 ); diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c index a1db8840e..12a122483 100644 --- a/programs/x509/cert_app.c +++ b/programs/x509/cert_app.c @@ -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 );