Skip to content

Commit 5d90bf4

Browse files
committed
ARMmbed#95 Ignore out of bounds read for the storage file
1 parent 2dbce5c commit 5d90bf4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

source/board/microbitv2/microbitv2.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ void vfs_user_build_filesystem_hook() {
582582
// File callback to be used with vfs_add_file to return file contents
583583
static uint32_t read_file_data_txt(uint32_t sector_offset, uint8_t *data, uint32_t num_sectors)
584584
{
585-
memcpy(data, (uint8_t *) (FLASH_STORAGE_ADDRESS + VFS_SECTOR_SIZE * sector_offset), VFS_SECTOR_SIZE);
585+
// Ignore out of bound reads
586+
if ( (FLASH_STORAGE_ADDRESS + VFS_SECTOR_SIZE * sector_offset) < (FLASH_CONFIG_ADDRESS + FLASH_INTERFACE_SIZE) ) {
587+
memcpy(data, (uint8_t *) (FLASH_STORAGE_ADDRESS + VFS_SECTOR_SIZE * sector_offset), VFS_SECTOR_SIZE);
588+
}
586589

587590
return VFS_SECTOR_SIZE;
588591
}

0 commit comments

Comments
 (0)