diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2018-01-22 16:14:44 +1100 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2018-01-22 16:14:44 +1100 |
commit | ba6d9c1a971db3c42bf0b054ebb64f72b3e3ddba (patch) | |
tree | 8ed033bc7e69f9e1a86b42bee6a87420ab23f54f /Bootloaders/MassStorage | |
parent | 8802907ce274489690f8edf169454f750c8efe57 (diff) | |
download | lufa-ba6d9c1a971db3c42bf0b054ebb64f72b3e3ddba.tar.gz lufa-ba6d9c1a971db3c42bf0b054ebb64f72b3e3ddba.tar.bz2 lufa-ba6d9c1a971db3c42bf0b054ebb64f72b3e3ddba.zip |
Fixed bootloaders accepting flash writes to the bootloader region (thanks to NicoHood).
Diffstat (limited to 'Bootloaders/MassStorage')
-rw-r--r-- | Bootloaders/MassStorage/BootloaderAPI.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Bootloaders/MassStorage/BootloaderAPI.c b/Bootloaders/MassStorage/BootloaderAPI.c index 5e8083ed3..c1e76d3bd 100644 --- a/Bootloaders/MassStorage/BootloaderAPI.c +++ b/Bootloaders/MassStorage/BootloaderAPI.c @@ -35,8 +35,20 @@ #include "BootloaderAPI.h" +static bool IsPageAddressValid(const uint32_t Address) +{ + /* Determine if the given page address is correctly aligned to the + start of a flash page. */ + bool PageAddressIsAligned = !(Address & (SPM_PAGESIZE - 1)); + + return (Address < BOOT_START_ADDR) && PageAddressIsAligned; +} + void BootloaderAPI_ErasePage(const uint32_t Address) { + if (! IsPageAddressValid(Address)) + return; + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { boot_page_erase_safe(Address); @@ -47,6 +59,9 @@ void BootloaderAPI_ErasePage(const uint32_t Address) void BootloaderAPI_WritePage(const uint32_t Address) { + if (! IsPageAddressValid(Address)) + return; + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { boot_page_write_safe(Address); |