2828#define EXT_FLASH
2929#define PART_UPDATE_EXT
3030#define NVM_FLASH_WRITEONCE
31+ #define WOLFBOOT_SELF_HEADER
3132
3233#if defined(ENCRYPT_WITH_AES256 ) || defined(ENCRYPT_WITH_AES128 )
3334 #define WOLFSSL_AES_COUNTER
6162#include "wolfssl/wolfcrypt/sha.h"
6263#include "wolfboot/wolfboot.h"
6364
65+ #ifndef ARCH_FLASH_OFFSET
66+ #define ARCH_FLASH_OFFSET WOLFBOOT_PARTITION_BOOT_ADDRESS
67+ #endif
68+
6469#include "unit-keystore.c"
6570
6671#include "image.c"
@@ -76,6 +81,11 @@ static int find_header_fail = 0;
7681static int find_header_called = 0 ;
7782static int find_header_mocked = 1 ;
7883
84+ uint8_t * wolfBoot_get_self_header (void )
85+ {
86+ return NULL ;
87+ }
88+
7989#if defined(WOLFBOOT_SIGN_ECC256 )
8090static const unsigned char pubkey_digest [SHA256_DIGEST_SIZE ] = {
8191 0x17 , 0x20 , 0xa5 , 0x9b , 0xe0 , 0x9b , 0x80 , 0x0c , 0xaa , 0xc4 , 0xf5 , 0x3f ,
@@ -606,6 +616,8 @@ START_TEST(test_open_image)
606616{
607617 struct wolfBoot_image img ;
608618 int ret ;
619+ uint8_t self_hdr [IMAGE_HEADER_SIZE ];
620+ uint32_t oversize ;
609621
610622
611623 /* invalid argument */
@@ -651,6 +663,17 @@ START_TEST(test_open_image)
651663 ck_assert_ptr_eq (img .hdr , (void * )WOLFBOOT_PARTITION_UPDATE_ADDRESS );
652664 ck_assert_ptr_eq (img .fw_base , (uint8_t * )WOLFBOOT_PARTITION_UPDATE_ADDRESS
653665 + 256 );
666+
667+ /* Self header must reject sizes beyond the partition payload budget */
668+ memset (self_hdr , 0xFF , sizeof (self_hdr ));
669+ ((uint32_t * )self_hdr )[0 ] = WOLFBOOT_MAGIC ;
670+ oversize = WOLFBOOT_PARTITION_SIZE - IMAGE_HEADER_SIZE + 1 ;
671+ ((uint32_t * )self_hdr )[1 ] = oversize ;
672+
673+ memset (& img , 0 , sizeof (img ));
674+ ret = wolfBoot_open_self_address (& img , self_hdr ,
675+ (uint8_t * )WOLFBOOT_PARTITION_BOOT_ADDRESS );
676+ ck_assert_int_eq (ret , -1 );
654677}
655678END_TEST
656679
0 commit comments