Skip to content

Commit

Permalink
Prevent writing past the end of flash
Browse files Browse the repository at this point in the history
Fixes issue #1 by making target_flash_program_array() test against the
end of the flash address space, as proposed by @perillamint
  • Loading branch information
devanlai committed Aug 18, 2017
1 parent a2cf981 commit cd4c37f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/stm32f103/target_stm32f103.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ bool target_flash_program_array(uint16_t* dest, const uint16_t* data, size_t hal
static uint16_t* erase_start;
static uint16_t* erase_end;

const uint16_t* flash_end = get_flash_end();
while (half_word_count > 0) {
/* Avoid writing past the end of flash */
if (dest >= flash_end) {
verified = false;
break;
}

if (dest >= erase_end || dest < erase_start) {
erase_start = get_flash_page_address(dest);
erase_end = erase_start + (FLASH_PAGE_SIZE)/sizeof(uint16_t);
Expand Down

0 comments on commit cd4c37f

Please # to comment.