mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 11:04:17 +01:00
Cleaned up location of init and free for some programs to prevent memory
leaks on incorrect arguments
This commit is contained in:
parent
993f02cda0
commit
3914840d78
@ -136,6 +136,8 @@ static int md5_check( char *filename )
|
||||
n = sizeof( line );
|
||||
}
|
||||
|
||||
fclose( f );
|
||||
|
||||
if( nb_err1 != 0 )
|
||||
{
|
||||
printf( "WARNING: %d (out of %d) input files could "
|
||||
|
@ -136,6 +136,8 @@ static int sha1_check( char *filename )
|
||||
n = sizeof( line );
|
||||
}
|
||||
|
||||
fclose( f );
|
||||
|
||||
if( nb_err1 != 0 )
|
||||
{
|
||||
printf( "WARNING: %d (out of %d) input files could "
|
||||
|
@ -136,6 +136,8 @@ static int sha2_check( char *filename )
|
||||
n = sizeof( line );
|
||||
}
|
||||
|
||||
fclose( f );
|
||||
|
||||
if( nb_err1 != 0 )
|
||||
{
|
||||
printf( "WARNING: %d (out of %d) input files could "
|
||||
|
@ -275,7 +275,9 @@ int main( int argc, char *argv[] )
|
||||
|
||||
exit:
|
||||
|
||||
net_close( server_fd );
|
||||
if( server_fd != -1 )
|
||||
net_close( server_fd );
|
||||
|
||||
rsa_free( &rsa );
|
||||
dhm_free( &dhm );
|
||||
|
||||
|
@ -69,6 +69,7 @@ int main( int argc, char *argv[] )
|
||||
((void) argv);
|
||||
|
||||
mpi_init( &G ); mpi_init( &P ); mpi_init( &Q );
|
||||
entropy_init( &entropy );
|
||||
|
||||
if( ( ret = mpi_read_string( &G, 10, GENERATOR ) ) != 0 )
|
||||
{
|
||||
@ -86,7 +87,6 @@ int main( int argc, char *argv[] )
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
|
@ -276,7 +276,9 @@ int main( int argc, char *argv[] )
|
||||
|
||||
exit:
|
||||
|
||||
net_close( client_fd );
|
||||
if( client_fd != -1 )
|
||||
net_close( client_fd );
|
||||
|
||||
rsa_free( &rsa );
|
||||
dhm_free( &dhm );
|
||||
|
||||
|
@ -62,7 +62,7 @@ int main( int argc, char *argv[] )
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
FILE *f;
|
||||
int ret;
|
||||
int ret = 1;
|
||||
rsa_context rsa;
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
@ -71,7 +71,8 @@ int main( int argc, char *argv[] )
|
||||
char filename[512];
|
||||
const char *pers = "rsa_sign_pss";
|
||||
|
||||
ret = 1;
|
||||
entropy_init( &entropy );
|
||||
rsa_init( &rsa, RSA_PKCS_V21, POLARSSL_MD_SHA1 );
|
||||
|
||||
if( argc != 3 )
|
||||
{
|
||||
@ -87,7 +88,6 @@ int main( int argc, char *argv[] )
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
@ -99,8 +99,6 @@ int main( int argc, char *argv[] )
|
||||
printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
rsa_init( &rsa, RSA_PKCS_V21, POLARSSL_MD_SHA1 );
|
||||
|
||||
if( ( ret = x509parse_keyfile( &rsa, argv[1], "" ) ) != 0 )
|
||||
{
|
||||
ret = 1;
|
||||
|
@ -59,14 +59,15 @@ int main( int argc, char *argv[] )
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
FILE *f;
|
||||
int ret;
|
||||
int ret = 1;
|
||||
size_t i;
|
||||
rsa_context rsa;
|
||||
unsigned char hash[20];
|
||||
unsigned char buf[POLARSSL_MPI_MAX_SIZE];
|
||||
char filename[512];
|
||||
|
||||
ret = 1;
|
||||
rsa_init( &rsa, RSA_PKCS_V21, POLARSSL_MD_SHA1 );
|
||||
|
||||
if( argc != 3 )
|
||||
{
|
||||
printf( "usage: rsa_verify_pss <key_file> <filename>\n" );
|
||||
@ -81,8 +82,6 @@ int main( int argc, char *argv[] )
|
||||
printf( "\n . Reading public key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
rsa_init( &rsa, RSA_PKCS_V21, POLARSSL_MD_SHA1 );
|
||||
|
||||
if( ( ret = x509parse_public_keyfile( &rsa, argv[1] ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! x509parse_public_key returned %d\n\n", ret );
|
||||
|
@ -279,8 +279,10 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
if( server_fd != -1 )
|
||||
net_close( server_fd );
|
||||
|
||||
x509_free( &cacert );
|
||||
net_close( server_fd );
|
||||
ssl_free( &ssl );
|
||||
|
||||
memset( &ssl, 0, sizeof( ssl ) );
|
||||
|
@ -110,6 +110,12 @@ int main( int argc, char *argv[] )
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
memset( &ssl, 0, sizeof(ssl_context) );
|
||||
|
||||
entropy_init( &entropy );
|
||||
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
||||
|
||||
signal( SIGCHLD, SIG_IGN );
|
||||
|
||||
/*
|
||||
@ -118,7 +124,6 @@ int main( int argc, char *argv[] )
|
||||
printf( "\n . Initial seeding of the random generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
@ -135,8 +140,6 @@ int main( int argc, char *argv[] )
|
||||
printf( " . Loading the server cert. and key..." );
|
||||
fflush( stdout );
|
||||
|
||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
||||
|
||||
/*
|
||||
* This demonstration program uses embedded test certificates.
|
||||
* Instead, you may want to use x509parse_crtfile() to read the
|
||||
@ -158,7 +161,6 @@ int main( int argc, char *argv[] )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
||||
ret = x509parse_key( &rsa, (const unsigned char *) test_srv_key,
|
||||
strlen( test_srv_key ), NULL, 0 );
|
||||
if( ret != 0 )
|
||||
@ -362,7 +364,9 @@ int main( int argc, char *argv[] )
|
||||
|
||||
exit:
|
||||
|
||||
net_close( client_fd );
|
||||
if( client_fd != -1 )
|
||||
net_close( client_fd );
|
||||
|
||||
x509_free( &srvcert );
|
||||
rsa_free( &rsa );
|
||||
ssl_free( &ssl );
|
||||
|
@ -101,9 +101,13 @@ int main( int argc, char *argv[] )
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
memset( &ssl, 0, sizeof(ssl_context) );
|
||||
#if defined(POLARSSL_SSL_CACHE_C)
|
||||
ssl_cache_init( &cache );
|
||||
#endif
|
||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
||||
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
||||
entropy_init( &entropy );
|
||||
|
||||
/*
|
||||
* 1. Load the certificates and private RSA key
|
||||
@ -111,8 +115,6 @@ int main( int argc, char *argv[] )
|
||||
printf( "\n . Loading the server cert. and key..." );
|
||||
fflush( stdout );
|
||||
|
||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
||||
|
||||
/*
|
||||
* This demonstration program uses embedded test certificates.
|
||||
* Instead, you may want to use x509parse_crtfile() to read the
|
||||
@ -134,7 +136,6 @@ int main( int argc, char *argv[] )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
||||
ret = x509parse_key( &rsa, (const unsigned char *) test_srv_key,
|
||||
strlen( test_srv_key ), NULL, 0 );
|
||||
if( ret != 0 )
|
||||
@ -165,7 +166,6 @@ int main( int argc, char *argv[] )
|
||||
printf( " . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
@ -353,7 +353,9 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
net_close( client_fd );
|
||||
if( client_fd != -1 )
|
||||
net_close( client_fd );
|
||||
|
||||
x509_free( &srvcert );
|
||||
rsa_free( &rsa );
|
||||
ssl_free( &ssl );
|
||||
|
@ -712,7 +712,10 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
net_close( client_fd );
|
||||
|
||||
if( client_fd != -1 )
|
||||
net_close( client_fd );
|
||||
|
||||
x509_free( &srvcert );
|
||||
x509_free( &cacert );
|
||||
rsa_free( &rsa );
|
||||
|
@ -172,7 +172,11 @@ static int ssl_test( struct options *opt )
|
||||
|
||||
ret = 1;
|
||||
|
||||
memset( &ssl, 0, sizeof(ssl_context) );
|
||||
entropy_init( &entropy );
|
||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
||||
memset( &rsa, 0, sizeof( rsa_context ) );
|
||||
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
@ -186,9 +190,6 @@ static int ssl_test( struct options *opt )
|
||||
memset( read_state, 0, sizeof( read_state ) );
|
||||
memset( write_state, 0, sizeof( write_state ) );
|
||||
|
||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
||||
memset( &rsa, 0, sizeof( rsa_context ) );
|
||||
|
||||
if( opt->opmode == OPMODE_CLIENT )
|
||||
{
|
||||
if( ( ret = net_connect( &client_fd, opt->server_name,
|
||||
@ -201,7 +202,7 @@ static int ssl_test( struct options *opt )
|
||||
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
||||
{
|
||||
printf( " ! ssl_init returned %d\n\n", ret );
|
||||
return( ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
||||
@ -408,7 +409,9 @@ exit:
|
||||
x509_free( &srvcert );
|
||||
rsa_free( &rsa );
|
||||
ssl_free( &ssl );
|
||||
net_close( client_fd );
|
||||
|
||||
if( client_fd != -1 )
|
||||
net_close( client_fd );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user