Skip to content

Commit 6efb152

Browse files
committed
fix(flash): Check for I/O failure during firmware file reading
1 parent 7901791 commit 6efb152

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/bl_install.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ int bootloader_install(FILE *fp)
6666
{
6767
u8 *firmware = calloc(FLASH_SIZE, 1);
6868
int read_bytes = fread(firmware, 1, FLASH_SIZE, fp); // this may be less than FLASH_SIZE (e.g. Pybricks has a small firmware image)
69+
if (ferror(fp)) {
70+
errmsg = "Reading of firmware file failed";
71+
free(firmware);
72+
return ERR_IO;
73+
}
74+
6975
int sector_count = (read_bytes + FLASH_SECTOR_SIZE - 1) / FLASH_SECTOR_SIZE;
7076

7177
printf("Programming %d EV3 flash sectors...\n", sector_count);

0 commit comments

Comments
 (0)