Skip to content

Commit 198e79d

Browse files
committed
cope better with broken saved code
1 parent fd9ec48 commit 198e79d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/jswrap_flash.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,12 @@ void jsfLoadFromFlash() {
374374
uint32_t cbData[2];
375375
jshFlashRead(&cbData[0], FLASH_SAVED_CODE_START, 4); // end address
376376
cbData[1] = FLASH_SAVED_CODE_START+4; // start address
377-
jsiConsolePrintf("Loading %d bytes from flash...\n", cbData[0]-FLASH_SAVED_CODE_START);
377+
uint32_t len = cbData[0]-FLASH_SAVED_CODE_START;
378+
if (len>1000000) {
379+
jsiConsolePrintf("Invalid saved code in flash!\n");
380+
return;
381+
}
382+
jsiConsolePrintf("Loading %d bytes from flash...\n", len);
378383
DECOMPRESS(jsfLoadFromFlash_readcb, cbData, (unsigned char*)basePtr);
379384
#endif
380385
}

0 commit comments

Comments
 (0)