1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-07 06:42:56 +03:00

Fix outcome file leak if execute_tests exits early

If there was a fatal error (bizarre behavior from the standard
library, or missing test data file), execute_tests did not close the
outcome file. Fix this.
This commit is contained in:
Gilles Peskine
2020-01-21 18:03:56 +01:00
parent 2ac4d86040
commit 9c673233bc

View File

@@ -525,15 +525,6 @@ int execute_tests( int argc , const char ** argv )
mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof( alloc_buf ) ); mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof( alloc_buf ) );
#endif #endif
if( outcome_file_name != NULL )
{
outcome_file = fopen( outcome_file_name, "a" );
if( outcome_file == NULL )
{
mbedtls_fprintf( stderr, "Unable to open outcome file. Continuing anyway.\n" );
}
}
/* /*
* The C standard doesn't guarantee that all-bits-0 is the representation * The C standard doesn't guarantee that all-bits-0 is the representation
* of a NULL pointer. We do however use that in our code for initializing * of a NULL pointer. We do however use that in our code for initializing
@@ -555,6 +546,15 @@ int execute_tests( int argc , const char ** argv )
return( 1 ); return( 1 );
} }
if( outcome_file_name != NULL )
{
outcome_file = fopen( outcome_file_name, "a" );
if( outcome_file == NULL )
{
mbedtls_fprintf( stderr, "Unable to open outcome file. Continuing anyway.\n" );
}
}
while( arg_index < argc ) while( arg_index < argc )
{ {
next_arg = argv[arg_index]; next_arg = argv[arg_index];
@@ -607,6 +607,8 @@ int execute_tests( int argc , const char ** argv )
{ {
mbedtls_fprintf( stderr, "Failed to open test file: %s\n", mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
test_filename ); test_filename );
if( outcome_file != NULL )
fclose( outcome_file );
return( 1 ); return( 1 );
} }