Skip to content

Commit 0a4f828

Browse files
committed
Addressed Fenrir's comments
1 parent 26552b5 commit 0a4f828

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/update_disk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ void RAMFUNCTION wolfBoot_start(void)
375375
uint32_t cur_ver = selected ? (uint32_t)pB_ver : (uint32_t)pA_ver;
376376
if ((max_ver > 0U) && (cur_ver < max_ver)) {
377377
wolfBoot_printf("Rollback to lower version not allowed\r\n");
378-
break;
378+
wolfBoot_panic();
379+
return;
379380
}
380381
}
381382
#endif
@@ -509,6 +510,7 @@ void RAMFUNCTION wolfBoot_start(void)
509510
#endif
510511
wolfBoot_printf("Unable to find a valid partition!\r\n");
511512
wolfBoot_panic();
513+
return;
512514
}
513515

514516
disk_close(BOOT_DISK);

src/update_flash_hwswap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void RAMFUNCTION wolfBoot_start(void)
6262
if ((max_v > 0U) && (active_v < max_v)) {
6363
wolfBoot_printf("Rollback to lower version not allowed\n");
6464
boot_panic();
65-
continue;
65+
return;
6666
}
6767
#endif
6868
if ((wolfBoot_open_image(&fw_image, active) < 0)

tools/unit-tests/unit-update-disk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ START_TEST(test_update_disk_rejects_rollback_after_higher_image_failure)
301301

302302
wolfBoot_start();
303303

304-
ck_assert_int_eq(wolfBoot_panicked, 1);
304+
ck_assert_int_gt(wolfBoot_panicked, 0);
305+
ck_assert_int_eq(mock_do_boot_called, 0);
305306
}
306307
END_TEST
307308

tools/unit-tests/unit-update-ram.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,26 @@ START_TEST (test_emergency_rollback_to_older_version_denied) {
438438
cleanup_flash();
439439
}
440440

441+
START_TEST (test_dualboot_candidate_rejects_testing_rollback_to_lower_version) {
442+
uint8_t testing_flags[5] = { IMG_STATE_TESTING, 'B', 'O', 'O', 'T' };
443+
int candidate;
444+
445+
reset_mock_stats();
446+
prepare_flash();
447+
add_payload(PART_BOOT, 2, TEST_SIZE_SMALL);
448+
add_payload(PART_UPDATE, 1, TEST_SIZE_SMALL);
449+
450+
ext_flash_unlock();
451+
ext_flash_write(WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - 5,
452+
testing_flags, 5);
453+
ext_flash_lock();
454+
455+
candidate = wolfBoot_dualboot_candidate();
456+
ck_assert_int_eq(candidate, -1);
457+
ck_assert_uint_eq(wolfBoot_current_firmware_version(), 0U);
458+
cleanup_flash();
459+
}
460+
441461
START_TEST (test_emergency_rollback_failure_due_to_bad_update) {
442462
uint8_t testing_flags[5] = { IMG_STATE_TESTING, 'B', 'O', 'O', 'T' };
443463
uint8_t wrong_update_magic[4] = { 'G', 'O', 'L', 'F' };
@@ -514,6 +534,8 @@ Suite *wolfboot_suite(void)
514534
TCase *update_toolarge = tcase_create("Update too large");
515535
TCase *invalid_sha = tcase_create("Invalid SHA digest");
516536
TCase *emergency_rollback = tcase_create("Emergency rollback");
537+
TCase *dualboot_candidate_rollback_denied =
538+
tcase_create("Dualboot candidate rollback denied");
517539
TCase *emergency_rollback_failure_due_to_bad_update = tcase_create("Emergency rollback failure due to bad update");
518540
TCase *empty_boot_partition_update = tcase_create("Empty boot partition update");
519541
TCase *empty_boot_but_update_sha_corrupted_denied = tcase_create("Empty boot partition but update SHA corrupted");
@@ -534,6 +556,8 @@ Suite *wolfboot_suite(void)
534556
tcase_add_test(update_toolarge, test_update_toolarge);
535557
tcase_add_test(invalid_sha, test_invalid_sha);
536558
tcase_add_test(emergency_rollback, test_emergency_rollback_to_older_version_denied);
559+
tcase_add_test(dualboot_candidate_rollback_denied,
560+
test_dualboot_candidate_rejects_testing_rollback_to_lower_version);
537561
tcase_add_test(emergency_rollback_failure_due_to_bad_update, test_emergency_rollback_failure_due_to_bad_update);
538562
tcase_add_test(empty_boot_partition_update, test_empty_boot_partition_update);
539563
tcase_add_test(empty_boot_but_update_sha_corrupted_denied, test_empty_boot_but_update_sha_corrupted_denied);
@@ -554,6 +578,7 @@ Suite *wolfboot_suite(void)
554578
suite_add_tcase(s, update_toolarge);
555579
suite_add_tcase(s, invalid_sha);
556580
suite_add_tcase(s, emergency_rollback);
581+
suite_add_tcase(s, dualboot_candidate_rollback_denied);
557582
suite_add_tcase(s, emergency_rollback_failure_due_to_bad_update);
558583
suite_add_tcase(s, empty_boot_partition_update);
559584
suite_add_tcase(s, empty_boot_but_update_sha_corrupted_denied);
@@ -574,6 +599,7 @@ Suite *wolfboot_suite(void)
574599
tcase_set_timeout(update_toolarge, 5);
575600
tcase_set_timeout(invalid_sha, 5);
576601
tcase_set_timeout(emergency_rollback, 5);
602+
tcase_set_timeout(dualboot_candidate_rollback_denied, 5);
577603
tcase_set_timeout(emergency_rollback_failure_due_to_bad_update, 5);
578604
tcase_set_timeout(empty_boot_partition_update, 5);
579605
tcase_set_timeout(empty_boot_but_update_sha_corrupted_denied, 5);

0 commit comments

Comments
 (0)