unit-tests: sector-align the update-trigger scrub fixture

wolfBoot_update_trigger() derives the staged sector by rounding the
update flags address down to a sector boundary and copies a full
sector from it. The g_sector fixture carried no sector alignment, so
the boundary landed inside the array and the copy read up to
4095 bytes past its end - the test passed only because the over-read
happened to fall in a neighboring global.

Align g_sector to WOLFBOOT_SECTOR_SIZE so the staged sector is the
array itself; the copy stays in bounds by construction.

Also ignore the generated unit-test extraction headers, as the other
generated sources in that list are.
pull/874/head
Daniele Lacamera 2026-08-26 19:01:41 +02:00
parent b115363291
commit ceae23e34f
2 changed files with 11 additions and 3 deletions

3
.gitignore vendored
View File

@ -492,12 +492,15 @@ tools/unit-tests/nxp_ls1028a_host.c
tools/unit-tests/nxp_p1021_host.c
tools/unit-tests/nxp_t10xx_fixup_extract.h
tools/unit-tests/sama5d3_read_extract.h
tools/unit-tests/samr21_erase_extract.h
tools/unit-tests/samr21_erase_fn_extract.h
tools/unit-tests/sdhci_host.c
tools/unit-tests/stm32l5_write_extract.h
tools/unit-tests/stm32u5_write_extract.h
tools/unit-tests/t10xx_qe_firmware_extract.h
tools/unit-tests/t2080_fman_extract.h
tools/unit-tests/ti_hercules_write_extract.h
tools/unit-tests/update_trigger_scrub_extract.h
tools/unit-tests/versal_ext_write_extract.h
tools/unit-tests/versal_host.c
tools/unit-tests/versal_host.h

View File

@ -52,13 +52,18 @@
static uint8_t NVM_CACHE[NVM_CACHE_SIZE];
/* The staged sector image: the boot/update trailer sector carrying
* the firmware key/nonce pattern at a fixed offset. */
* the firmware key/nonce pattern at a fixed offset. Sector-aligned:
* wolfBoot_update_trigger() derives the staged sector by rounding the
* flag address down to a sector boundary, and the sector copy must
* stay inside this array. */
#define KEY_OFF 0x0F00
#define KEY_LEN 64
static uint8_t g_sector[NVM_CACHE_SIZE];
static uint8_t g_sector[NVM_CACHE_SIZE]
__attribute__((aligned(WOLFBOOT_SECTOR_SIZE)));
/* The update partition flags end at the top of the staged sector, so
* lastSector in wolfBoot_update_trigger() resolves to g_sector. */
* lastSector in wolfBoot_update_trigger() resolves to the base of
* g_sector (the alignment above makes that true by construction). */
#define PART_UPDATE_ENDFLAGS ((uintptr_t)(g_sector + WOLFBOOT_SECTOR_SIZE))
/* Stubbed flash layer: records calls. */