mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-07-06 20:47:55 +02:00
Fix flash bounds check
This commit is contained in:
@@ -123,6 +123,10 @@ static void flash_erase_program_ram(const FlashRomFns *fns, uint32_t offset,
|
||||
|
||||
void flash_write(uint32_t offset, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (data == NULL || offset >= FLASH_SIZE)
|
||||
return;
|
||||
if (len > FLASH_SIZE - offset)
|
||||
len = FLASH_SIZE - offset;
|
||||
FlashRomFns fns;
|
||||
lookup_rom_fns(&fns);
|
||||
uint32_t primask;
|
||||
@@ -134,6 +138,10 @@ void flash_write(uint32_t offset, const uint8_t *data, uint32_t len)
|
||||
|
||||
void flash_read(uint32_t offset, uint8_t *out, uint32_t len)
|
||||
{
|
||||
if (out == NULL || offset >= FLASH_SIZE)
|
||||
return;
|
||||
if (len > FLASH_SIZE - offset)
|
||||
len = FLASH_SIZE - offset;
|
||||
const uint8_t *src = (const uint8_t *)(XIP_BASE + offset);
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
out[i] = src[i];
|
||||
|
||||
Reference in New Issue
Block a user