Skip to content

Commit 131d957

Browse files
committed
fix: Bounds checking for common crc32 calculation func, bump preloader to v1.1
1 parent 71c7cb5 commit 131d957

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

firmware/common/bootloader.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ uint32_t calculateCrc32(uint8_t *data, uint32_t len) {
1515
return 0xFFFFFFFF;
1616
}
1717

18+
uintptr_t addr = (uintptr_t)data;
19+
20+
/* Require 32-bit words and word alignment */
21+
if ((len % 4) != 0) return 0xFFFFFFFF;
22+
if ((addr % 4) != 0) return 0xFFFFFFFF;
23+
24+
/* Bounds check (overflow-safe): addr + len must fit inside flash */
25+
if (addr < FLASH_BASE) return 0xFFFFFFFF;
26+
if (addr > ((FLASH_BASE + FLASH_SIZE) - len)) return 0xFFFFFFFF;
27+
1828
/* Configure and reset CRC peripheral: use default algorithm */
1929
CRC->CR = CRC_CR_RESET;
2030

firmware/preloader/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ __attribute__((used))
1212
const tombstone_t tombstone = {
1313
.magic = IAPL_MAGIC,
1414
.ver_major = 1,
15-
.ver_minor = 0,
15+
.ver_minor = 1,
1616
.size = 0x5A53, // ASCII: SZ
1717
.crc = 0x00435243, // ASCII: CRC + \0
1818
.reserved = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },

0 commit comments

Comments
 (0)