Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/device_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ int eos_device_table_validate(const eos_device_table_t *table)
if (!table) return EOS_ERR_INVALID;
if (table->magic != EOS_DEVTABLE_MAGIC) return EOS_ERR_INVALID;
if (table->version != EOS_DEVTABLE_VERSION) return EOS_ERR_VERSION;
if (table->mem_region_count > EOS_MAX_MEM_REGIONS) return EOS_ERR_INVALID;
if (table->periph_count > EOS_MAX_PERIPHERALS) return EOS_ERR_INVALID;

uint32_t expected = compute_table_crc(table);
if (table->crc32 != expected) return EOS_ERR_CRC;
Expand Down
19 changes: 18 additions & 1 deletion tests/unit/test_device_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ TEST(test_corrupt_crc_fails)
ASSERT(eos_device_table_validate(&table) == EOS_ERR_CRC);
}

TEST(test_oversized_counts_fail)
{
eos_device_table_t table;
eos_device_table_init(&table, "Oversized");
table.mem_region_count = EOS_MAX_MEM_REGIONS + 1;
eos_device_table_finalize(&table);

ASSERT(eos_device_table_validate(&table) == EOS_ERR_INVALID);

table.mem_region_count = 0;
table.periph_count = EOS_MAX_PERIPHERALS + 1;
eos_device_table_finalize(&table);

ASSERT(eos_device_table_validate(&table) == EOS_ERR_INVALID);
}

int main(void)
{
printf("=== eBootloader: Device Table Unit Tests ===\n\n");
Expand All @@ -127,8 +143,9 @@ int main(void)
run_test_memory_overflow();
run_test_finalize_and_validate();
run_test_corrupt_crc_fails();
run_test_oversized_counts_fail();

tests_run = 7;
tests_run = 8;
printf("\n%d/%d tests passed\n", tests_passed, tests_run);
return (tests_passed == tests_run) ? 0 : 1;
}