|
34 | 34 |
|
35 | 35 | #include <stdio.h> |
36 | 36 | #include <stdlib.h> |
| 37 | +#include <limits.h> |
37 | 38 | #include "user_settings.h" |
38 | 39 | #include "wolfboot/wolfboot.h" |
39 | 40 | #include "libwolfboot.c" |
@@ -834,6 +835,25 @@ START_TEST (test_diffbase_version_reads) |
834 | 835 | } |
835 | 836 | END_TEST |
836 | 837 |
|
| 838 | +START_TEST (test_get_total_size_preserves_uint32_range) |
| 839 | +{ |
| 840 | + struct wolfBoot_image boot; |
| 841 | + struct wolfBoot_image update; |
| 842 | + uint32_t total_size; |
| 843 | + |
| 844 | + memset(&boot, 0, sizeof(boot)); |
| 845 | + memset(&update, 0, sizeof(update)); |
| 846 | + |
| 847 | + boot.fw_size = (uint32_t)INT_MAX - IMAGE_HEADER_SIZE + 1u; |
| 848 | + update.fw_size = boot.fw_size + 7u; |
| 849 | + |
| 850 | + total_size = wolfBoot_get_total_size(&boot, &update); |
| 851 | + |
| 852 | + ck_assert_uint_eq(total_size, update.fw_size + IMAGE_HEADER_SIZE); |
| 853 | + ck_assert(total_size > (uint32_t)INT_MAX); |
| 854 | +} |
| 855 | +END_TEST |
| 856 | + |
837 | 857 | #ifdef DELTA_UPDATES |
838 | 858 | START_TEST (test_delta_zero_size_valid_header_rejected_without_recovery_heuristic) |
839 | 859 | { |
@@ -933,6 +953,7 @@ Suite *wolfboot_suite(void) |
933 | 953 | TCase *empty_boot_but_update_sha_corrupted_denied = tcase_create("Empty boot partition but update SHA corrupted"); |
934 | 954 | TCase *swap_resume = tcase_create("Swap resume noop"); |
935 | 955 | TCase *diffbase_version = tcase_create("Diffbase version lookup"); |
| 956 | + TCase *get_total_size = tcase_create("Total size range"); |
936 | 957 | TCase *boot_success = tcase_create("Boot success state"); |
937 | 958 | #ifdef DELTA_UPDATES |
938 | 959 | TCase *delta_zero_size = tcase_create("Delta zero size"); |
@@ -974,6 +995,7 @@ Suite *wolfboot_suite(void) |
974 | 995 | tcase_add_test(empty_boot_but_update_sha_corrupted_denied, test_empty_boot_but_update_sha_corrupted_denied); |
975 | 996 | tcase_add_test(swap_resume, test_swap_resume_noop); |
976 | 997 | tcase_add_test(diffbase_version, test_diffbase_version_reads); |
| 998 | + tcase_add_test(get_total_size, test_get_total_size_preserves_uint32_range); |
977 | 999 | tcase_add_test(boot_success, test_boot_success_sets_state); |
978 | 1000 | #ifdef DELTA_UPDATES |
979 | 1001 | tcase_add_test(delta_zero_size, test_delta_zero_size_valid_header_rejected_without_recovery_heuristic); |
@@ -1007,6 +1029,7 @@ Suite *wolfboot_suite(void) |
1007 | 1029 | suite_add_tcase(s, empty_boot_but_update_sha_corrupted_denied); |
1008 | 1030 | suite_add_tcase(s, swap_resume); |
1009 | 1031 | suite_add_tcase(s, diffbase_version); |
| 1032 | + suite_add_tcase(s, get_total_size); |
1010 | 1033 | suite_add_tcase(s, boot_success); |
1011 | 1034 | #ifdef DELTA_UPDATES |
1012 | 1035 | suite_add_tcase(s, delta_zero_size); |
|
0 commit comments