Skip to content

Commit 2939d30

Browse files
committed
bootutil: loader: Verify image header before checking image
Changes the order of operations to validate the image header before checking the image, it does not make sense to check the image if the header itself is invalid Signed-off-by: Jamie McCrae <[email protected]>
1 parent dbb5c78 commit 2939d30

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

boot/bootutil/src/loader.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,13 +1030,16 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
10301030
}
10311031
}
10321032
#endif
1033-
BOOT_HOOK_CALL_FIH(boot_image_check_hook, FIH_BOOT_HOOK_REGULAR,
1034-
fih_rc, BOOT_CURR_IMG(state), slot);
1035-
if (FIH_EQ(fih_rc, FIH_BOOT_HOOK_REGULAR))
1036-
{
1037-
FIH_CALL(boot_image_check, fih_rc, state, hdr, fap, bs);
1033+
if (!boot_is_header_valid(hdr, fap, state)) {
1034+
fih_rc = FIH_FAILURE;
1035+
} else {
1036+
BOOT_HOOK_CALL_FIH(boot_image_check_hook, FIH_BOOT_HOOK_REGULAR,
1037+
fih_rc, BOOT_CURR_IMG(state), slot);
1038+
if (FIH_EQ(fih_rc, FIH_BOOT_HOOK_REGULAR)) {
1039+
FIH_CALL(boot_image_check, fih_rc, state, hdr, fap, bs);
1040+
}
10381041
}
1039-
if (!boot_is_header_valid(hdr, fap, state) || FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
1042+
if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
10401043
if ((slot != BOOT_PRIMARY_SLOT) || ARE_SLOTS_EQUIVALENT()) {
10411044
flash_area_erase(fap, 0, flash_area_get_size(fap));
10421045
/* Image is invalid, erase it to prevent further unnecessary

0 commit comments

Comments
 (0)