@@ -362,6 +362,43 @@ START_TEST(test_get_update_sector_flag_rejects_invalid_magic)
362362}
363363END_TEST
364364
365+ START_TEST (test_update_sector_flag_high_index_does_not_alias_low_index )
366+ {
367+ int ret ;
368+ uint8_t st = 0 ;
369+
370+ ret = mmap_file ("/tmp/wolfboot-unit-high-index.bin" , (void * )MOCK_ADDRESS ,
371+ WOLFBOOT_PARTITION_SIZE , NULL );
372+ ck_assert (ret >= 0 );
373+ #ifdef FLAGS_HOME
374+ ret = mmap_file ("/tmp/wolfboot-unit-high-index-int.bin" ,
375+ (void * )MOCK_ADDRESS_BOOT , WOLFBOOT_PARTITION_SIZE , NULL );
376+ ck_assert (ret >= 0 );
377+ #endif
378+ ret = mmap_file ("/tmp/wolfboot-unit-high-index-swap.bin" ,
379+ (void * )MOCK_ADDRESS_SWAP , WOLFBOOT_SECTOR_SIZE , NULL );
380+ ck_assert (ret >= 0 );
381+
382+ hal_flash_unlock ();
383+ wolfBoot_erase_partition (PART_UPDATE );
384+
385+ ret = wolfBoot_set_update_sector_flag (1 , SECT_FLAG_SWAPPING );
386+ ck_assert_int_eq (ret , 0 );
387+ ret = wolfBoot_set_update_sector_flag (512 , SECT_FLAG_UPDATED );
388+ ck_assert_int_eq (ret , 0 );
389+
390+ ret = wolfBoot_get_update_sector_flag (1 , & st );
391+ ck_assert_int_eq (ret , 0 );
392+ ck_assert_uint_eq (st , SECT_FLAG_SWAPPING );
393+
394+ ret = wolfBoot_get_update_sector_flag (512 , & st );
395+ ck_assert_int_eq (ret , 0 );
396+ ck_assert_uint_eq (st , SECT_FLAG_UPDATED );
397+
398+ hal_flash_lock ();
399+ }
400+ END_TEST
401+
365402
366403Suite * wolfboot_suite (void )
367404{
@@ -375,6 +412,8 @@ Suite *wolfboot_suite(void)
375412 test_partition_magic_write_stops_on_flash_write_error );
376413 tcase_add_test (nvm_select_fresh_sector ,
377414 test_get_update_sector_flag_rejects_invalid_magic );
415+ tcase_add_test (nvm_select_fresh_sector ,
416+ test_update_sector_flag_high_index_does_not_alias_low_index );
378417 suite_add_tcase (s , nvm_select_fresh_sector );
379418
380419 return s ;
0 commit comments