Skip to content

Commit 35142e6

Browse files
committed
Fix total size type in update flash
F/2269
1 parent e4e96ad commit 35142e6

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/update_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
786786
#ifdef __CCRX__
787787
#pragma section FRAM
788788
#endif
789-
static int wolfBoot_get_total_size(struct wolfBoot_image* boot,
789+
static uint32_t wolfBoot_get_total_size(struct wolfBoot_image* boot,
790790
struct wolfBoot_image* update)
791791
{
792792
uint32_t total_size = 0;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <stdio.h>
3636
#include <stdlib.h>
37+
#include <limits.h>
3738
#include "user_settings.h"
3839
#include "wolfboot/wolfboot.h"
3940
#include "libwolfboot.c"
@@ -834,6 +835,25 @@ START_TEST (test_diffbase_version_reads)
834835
}
835836
END_TEST
836837

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+
837857
#ifdef DELTA_UPDATES
838858
START_TEST (test_delta_zero_size_valid_header_rejected_without_recovery_heuristic)
839859
{
@@ -933,6 +953,7 @@ Suite *wolfboot_suite(void)
933953
TCase *empty_boot_but_update_sha_corrupted_denied = tcase_create("Empty boot partition but update SHA corrupted");
934954
TCase *swap_resume = tcase_create("Swap resume noop");
935955
TCase *diffbase_version = tcase_create("Diffbase version lookup");
956+
TCase *get_total_size = tcase_create("Total size range");
936957
TCase *boot_success = tcase_create("Boot success state");
937958
#ifdef DELTA_UPDATES
938959
TCase *delta_zero_size = tcase_create("Delta zero size");
@@ -974,6 +995,7 @@ Suite *wolfboot_suite(void)
974995
tcase_add_test(empty_boot_but_update_sha_corrupted_denied, test_empty_boot_but_update_sha_corrupted_denied);
975996
tcase_add_test(swap_resume, test_swap_resume_noop);
976997
tcase_add_test(diffbase_version, test_diffbase_version_reads);
998+
tcase_add_test(get_total_size, test_get_total_size_preserves_uint32_range);
977999
tcase_add_test(boot_success, test_boot_success_sets_state);
9781000
#ifdef DELTA_UPDATES
9791001
tcase_add_test(delta_zero_size, test_delta_zero_size_valid_header_rejected_without_recovery_heuristic);
@@ -1007,6 +1029,7 @@ Suite *wolfboot_suite(void)
10071029
suite_add_tcase(s, empty_boot_but_update_sha_corrupted_denied);
10081030
suite_add_tcase(s, swap_resume);
10091031
suite_add_tcase(s, diffbase_version);
1032+
suite_add_tcase(s, get_total_size);
10101033
suite_add_tcase(s, boot_success);
10111034
#ifdef DELTA_UPDATES
10121035
suite_add_tcase(s, delta_zero_size);

0 commit comments

Comments
 (0)