mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 10:05:46 +01:00
Merge pull request #3164 from ronald-cron-arm/unmet-dependencies-buffer-overflow-fix-2.16
[backport 2.16] Unmet dependencies buffer overflow fix
This commit is contained in:
commit
a8bc32872a
@ -229,6 +229,40 @@ typedef enum
|
|||||||
mbedtls_exit( 1 ); \
|
mbedtls_exit( 1 ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
/* Test if arg and &(arg)[0] have the same type. This is true if arg is
|
||||||
|
* an array but not if it's a pointer. */
|
||||||
|
#define IS_ARRAY_NOT_POINTER( arg ) \
|
||||||
|
( ! __builtin_types_compatible_p( __typeof__( arg ), \
|
||||||
|
__typeof__( &( arg )[0] ) ) )
|
||||||
|
#else
|
||||||
|
/* On platforms where we don't know how to implement this check,
|
||||||
|
* omit it. Oh well, a non-portable check is better than nothing. */
|
||||||
|
#define IS_ARRAY_NOT_POINTER( arg ) 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* A compile-time constant with the value 0. If `const_expr` is not a
|
||||||
|
* compile-time constant with a nonzero value, cause a compile-time error. */
|
||||||
|
#define STATIC_ASSERT_EXPR( const_expr ) \
|
||||||
|
( 0 && sizeof( struct { int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) )
|
||||||
|
/* Return the scalar value `value` (possibly promoted). This is a compile-time
|
||||||
|
* constant if `value` is. `condition` must be a compile-time constant.
|
||||||
|
* If `condition` is false, arrange to cause a compile-time error. */
|
||||||
|
#define STATIC_ASSERT_THEN_RETURN( condition, value ) \
|
||||||
|
( STATIC_ASSERT_EXPR( condition ) ? 0 : ( value ) )
|
||||||
|
|
||||||
|
#define ARRAY_LENGTH_UNSAFE( array ) \
|
||||||
|
( sizeof( array ) / sizeof( *( array ) ) )
|
||||||
|
/** Return the number of elements of a static or stack array.
|
||||||
|
*
|
||||||
|
* \param array A value of array (not pointer) type.
|
||||||
|
*
|
||||||
|
* \return The number of elements of the array.
|
||||||
|
*/
|
||||||
|
#define ARRAY_LENGTH( array ) \
|
||||||
|
( STATIC_ASSERT_THEN_RETURN( IS_ARRAY_NOT_POINTER( array ), \
|
||||||
|
ARRAY_LENGTH_UNSAFE( array ) ) )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 32-bit integer manipulation macros (big endian)
|
* 32-bit integer manipulation macros (big endian)
|
||||||
*/
|
*/
|
||||||
|
@ -385,15 +385,16 @@ int execute_tests( int argc , const char ** argv )
|
|||||||
const char *default_filename = "DATA_FILE";
|
const char *default_filename = "DATA_FILE";
|
||||||
const char *test_filename = NULL;
|
const char *test_filename = NULL;
|
||||||
const char **test_files = NULL;
|
const char **test_files = NULL;
|
||||||
int testfile_count = 0;
|
size_t testfile_count = 0;
|
||||||
int option_verbose = 0;
|
int option_verbose = 0;
|
||||||
int function_id = 0;
|
int function_id = 0;
|
||||||
|
|
||||||
/* Other Local variables */
|
/* Other Local variables */
|
||||||
int arg_index = 1;
|
int arg_index = 1;
|
||||||
const char *next_arg;
|
const char *next_arg;
|
||||||
int testfile_index, ret, i, cnt;
|
size_t testfile_index, i, cnt;
|
||||||
int total_errors = 0, total_tests = 0, total_skipped = 0;
|
int ret;
|
||||||
|
unsigned total_errors = 0, total_tests = 0, total_skipped = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char buf[5000];
|
char buf[5000];
|
||||||
char *params[50];
|
char *params[50];
|
||||||
@ -473,8 +474,9 @@ int execute_tests( int argc , const char ** argv )
|
|||||||
testfile_index < testfile_count;
|
testfile_index < testfile_count;
|
||||||
testfile_index++ )
|
testfile_index++ )
|
||||||
{
|
{
|
||||||
int unmet_dep_count = 0;
|
size_t unmet_dep_count = 0;
|
||||||
int unmet_dependencies[20];
|
int unmet_dependencies[20];
|
||||||
|
int missing_unmet_dependencies = 0;
|
||||||
|
|
||||||
test_filename = test_files[ testfile_index ];
|
test_filename = test_files[ testfile_index ];
|
||||||
|
|
||||||
@ -495,6 +497,7 @@ int execute_tests( int argc , const char ** argv )
|
|||||||
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
unmet_dep_count = 0;
|
unmet_dep_count = 0;
|
||||||
|
missing_unmet_dependencies = 0;
|
||||||
|
|
||||||
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
||||||
break;
|
break;
|
||||||
@ -520,8 +523,16 @@ int execute_tests( int argc , const char ** argv )
|
|||||||
int dep_id = strtol( params[i], NULL, 10 );
|
int dep_id = strtol( params[i], NULL, 10 );
|
||||||
if( dep_check( dep_id ) != DEPENDENCY_SUPPORTED )
|
if( dep_check( dep_id ) != DEPENDENCY_SUPPORTED )
|
||||||
{
|
{
|
||||||
unmet_dependencies[unmet_dep_count] = dep_id;
|
if( unmet_dep_count <
|
||||||
unmet_dep_count++;
|
ARRAY_LENGTH( unmet_dependencies ) )
|
||||||
|
{
|
||||||
|
unmet_dependencies[unmet_dep_count] = dep_id;
|
||||||
|
unmet_dep_count++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
missing_unmet_dependencies = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,11 +601,14 @@ int execute_tests( int argc , const char ** argv )
|
|||||||
mbedtls_fprintf( stdout, "%d ",
|
mbedtls_fprintf( stdout, "%d ",
|
||||||
unmet_dependencies[i] );
|
unmet_dependencies[i] );
|
||||||
}
|
}
|
||||||
|
if( missing_unmet_dependencies )
|
||||||
|
mbedtls_fprintf( stdout, "..." );
|
||||||
}
|
}
|
||||||
mbedtls_fprintf( stdout, "\n" );
|
mbedtls_fprintf( stdout, "\n" );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
unmet_dep_count = 0;
|
unmet_dep_count = 0;
|
||||||
|
missing_unmet_dependencies = 0;
|
||||||
}
|
}
|
||||||
else if( ret == DISPATCH_TEST_SUCCESS )
|
else if( ret == DISPATCH_TEST_SUCCESS )
|
||||||
{
|
{
|
||||||
@ -641,8 +655,8 @@ int execute_tests( int argc , const char ** argv )
|
|||||||
else
|
else
|
||||||
mbedtls_fprintf( stdout, "FAILED" );
|
mbedtls_fprintf( stdout, "FAILED" );
|
||||||
|
|
||||||
mbedtls_fprintf( stdout, " (%d / %d tests (%d skipped))\n",
|
mbedtls_fprintf( stdout, " (%u / %u tests (%u skipped))\n",
|
||||||
total_tests - total_errors, total_tests, total_skipped );
|
total_tests - total_errors, total_tests, total_skipped );
|
||||||
|
|
||||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||||
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
||||||
|
Loading…
Reference in New Issue
Block a user