From ceae23e34fc4f9695c4898fe04e59cdb8a361540 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 26 Aug 2026 19:01:41 +0200 Subject: [PATCH] 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. --- .gitignore | 3 +++ tools/unit-tests/unit-update-trigger-scrub.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7d474844..890f1a44 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/tools/unit-tests/unit-update-trigger-scrub.c b/tools/unit-tests/unit-update-trigger-scrub.c index e35ec8e9..b69d5585 100644 --- a/tools/unit-tests/unit-update-trigger-scrub.c +++ b/tools/unit-tests/unit-update-trigger-scrub.c @@ -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. */