Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions boot/bootutil/src/bootutil_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ boot_swap_type_multi(int image_index)
int rc;
size_t i;

if (image_index >= BOOT_IMAGE_NUMBER) {
return BOOT_SWAP_TYPE_PANIC;
}

if (FLASH_AREA_IMAGE_PRIMARY(image_index) ==
FLASH_AREA_IMAGE_SECONDARY(image_index)) {
BOOT_LOG_INF("Image index: %d, aliased slots; Swap type: none", image_index);
Expand Down
11 changes: 11 additions & 0 deletions boot/zephyr/include/sysflash/sysflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <zephyr/devicetree.h>
#include <zephyr/storage/flash_map.h>
#include <zephyr/sys/util_macro.h>
#include <assert.h>

#ifndef SOC_FLASH_0_ID
#define SOC_FLASH_0_ID 0
Expand Down Expand Up @@ -163,6 +164,16 @@ static inline uint32_t __flash_area_ids_for_slot(int img, int slot)
SECOND_STAGE_INACTIVE_MCUBOOT_ID, PARTITION_ID(slot1_partition)
#endif
};
#ifdef CONFIG_ASSERT
assert(img * 2 + slot < ARRAY_SIZE(all_slots));
#else
/* Since there is no way to indicate a misuse of this function,
* return the first partition to avoid undefined behavior.
*/
if (img * 2 + slot >= ARRAY_SIZE(all_slots)) {
return all_slots[0];
}
#endif
return all_slots[img * 2 + slot];
};

Expand Down
Loading