unit tests: Fix potential buffer overflow

Fix potential buffer overflow when tracking the unmet dependencies
of a test case. The identifiers of unmet dependencies are stored
in an array of fixed size. Ensure that we don't overrun the array.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-04-03 15:36:16 +02:00
parent 59f2139df0
commit 1d3eab684c

View file

@ -393,18 +393,22 @@ int main(int argc, const char *argv[])
{
if( dep_check( params[i] ) != DEPENDENCY_SUPPORTED )
{
if( 0 != option_verbose )
if( unmet_dep_count <
ARRAY_LENGTH( unmet_dependencies ) )
{
unmet_dependencies[unmet_dep_count] =
strdup( params[i] );
if( unmet_dependencies[unmet_dep_count] == NULL )
if( 0 != option_verbose )
{
mbedtls_fprintf( stderr,
"FATAL: Out of memory\n" );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
unmet_dependencies[unmet_dep_count] =
strdup( params[i] );
if( unmet_dependencies[unmet_dep_count] == NULL )
{
mbedtls_fprintf( stderr,
"FATAL: Out of memory\n" );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
}
unmet_dep_count++;
}
unmet_dep_count++;
}
}