Skip to content

Commit 2f5216f

Browse files
committed
fix(flash): Check for I/O failure during firmware file reading
1 parent 9b98858 commit 2f5216f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/bl_install.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,11 @@ static int bootloader_send(FILE *fp, int length, u32* pCrc32)
261261
int bootloader_crc(FILE *fp, u32 starting_sector, u32 num_sectors, bool verbose)
262262
{
263263
u8 *firmware = calloc(FLASH_SIZE, 1);
264-
int read_bytes = fread(firmware, 1, FLASH_SIZE, fp);
265-
if (read_bytes != FLASH_SIZE) {
266-
printf("WARNING: firmware file might be truncated: %d bytes expected, %d bytes read\n", FLASH_SIZE, read_bytes);
264+
fread(firmware, 1, FLASH_SIZE, fp);
265+
if (ferror(fp)) {
266+
errmsg = "Reading of firmware file failed";
267+
free(firmware);
268+
return ERR_IO;
267269
}
268270

269271
int err = ERR_UNK;

0 commit comments

Comments
 (0)