From 1d3eab684c1466d32d6825cdff856e0346317a79 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Fri, 3 Apr 2020 15:36:16 +0200 Subject: [PATCH] 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 --- tests/suites/main_test.function | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index 1fc76bd30..57e8c8305 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -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++; } }