Skip to content

Commit

Permalink
Fix nasa#164, consistent "chunk" test sizes
Browse files Browse the repository at this point in the history
Do not use a random uint16 to size the structure that is allocated
on the stack.  Pick a reasonable size that is not likely to overrun
the stack, and use it.

This fixes a crash/stack overrun issue when running on RTEMS.
  • Loading branch information
jphickey committed Jan 12, 2022
1 parent d3ae3f9 commit bc1b4c9
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions unit-test/cf_chunk_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1910,11 +1910,9 @@ void Test_CF_Chunks_Init_SetGiven_chunks_max_chunks_ToGiven_max_chunks(void)
{
/* Arrange */
CF_ChunkList_t dummy_chunks;
CF_ChunkList_t *arg_chunks = &dummy_chunks;
CF_ChunkIdx_t arg_max_chunks =
Any_uint16() + 2; /* 2-65537, uint8 is used instead of CF_ChunkIdx_t to have a reasonably
decent size for the test without being too large (segfault) */
CF_Chunk_t arg_chunks_mem[arg_max_chunks];
CF_ChunkList_t *arg_chunks = &dummy_chunks;
CF_ChunkIdx_t arg_max_chunks = 14;
CF_Chunk_t arg_chunks_mem[14];

arg_chunks->count = 0;

Expand Down Expand Up @@ -1943,11 +1941,9 @@ void Test_CF_ChunksReset_Set_count_To_0_Keeps_max_chunks_AndMemsets_chunks_ToAll
{
/* Arrange */
CF_ChunkList_t dummy_chunks;
CF_ChunkList_t *arg_chunks = &dummy_chunks;
CF_ChunkIdx_t initial_max_chunks =
Any_uint16() + 2; /* 2-65537, uint8 is used instead of CF_ChunkIdx_t to have a reasonably
decent size for the test without being too large (segfault) */
CF_Chunk_t dummy_chunks_chunks[initial_max_chunks];
CF_ChunkList_t *arg_chunks = &dummy_chunks;
CF_ChunkIdx_t initial_max_chunks = 17;
CF_Chunk_t dummy_chunks_chunks[17];

arg_chunks->count = Any_index_t();
arg_chunks->max_chunks = initial_max_chunks;
Expand Down

0 comments on commit bc1b4c9

Please sign in to comment.