Skip to content

Commit

Permalink
Fix integer overflow in benchmark program
Browse files Browse the repository at this point in the history
When building with MBEDTLS_MEMORY_DEBUG enabled, and running the ecdh part,
the benchmark program would start writing a very large number of space
characters on stdout, and would have to be killed because it never seemed to
terminate.

This was due to an integer overflow in computing how many space to leave after
the title in order to get memory measurements aligned, which resulted in up
to SIZE_MAX spaces being printed.

This commit just fixes the overflow, the next commit is going to fix the magic
number (12).

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
  • Loading branch information
mpg committed Apr 9, 2020
1 parent 4500e83 commit e52fd3f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion programs/test/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ do { \

#define MEMORY_MEASURE_PRINT( title_len ) \
mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \
for( ii = 12 - (title_len); ii != 0; ii-- ) mbedtls_printf( " " ); \
for( ii = 12 > (title_len) ? 12 - (title_len) : 1; ii !=0; ii--) \
mbedtls_printf( " " ); \
max_used -= prv_used; \
max_blocks -= prv_blocks; \
max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \
Expand Down

0 comments on commit e52fd3f

Please sign in to comment.