Skip to content

Commit 53e0193

Browse files
committed
add magic byte check for Update class
Note: only check of first 0xE9 possible.
1 parent a04c225 commit 53e0193

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cores/esp8266/Updater.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@ size_t UpdaterClass::writeStream(Stream &data) {
252252
if(hasError() || !isRunning())
253253
return 0;
254254

255+
// check for valid first magic byte (is always 0xE9)
256+
if(data.peek() != 0xE9) {
257+
_error = UPDATE_ERROR_MAGIC_BYTE;
258+
_currentAddress = (_startAddress + _size);
259+
#ifdef DEBUG_UPDATER
260+
printError(DEBUG_UPDATER);
261+
#endif
262+
return 0;
263+
}
264+
255265
while(remaining()) {
256266
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
257267
if(toRead == 0) { //Timeout
@@ -293,6 +303,8 @@ void UpdaterClass::printError(Stream &out){
293303
out.println("MD5 Check Failed");
294304
} else if(_error == UPDATE_ERROR_FLASH_CONFIG){
295305
out.printf("Flash config wrong real: %d IDE: %d\n", ESP.getFlashChipRealSize(), ESP.getFlashChipSize());
306+
} else if(_error == UPDATE_ERROR_MAGIC_BYTE){
307+
out.println("Magic byte is wrong, not 0xE9");
296308
} else {
297309
out.println("UNKNOWN");
298310
}

cores/esp8266/Updater.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define UPDATE_ERROR_STREAM (5)
1414
#define UPDATE_ERROR_MD5 (6)
1515
#define UPDATE_ERROR_FLASH_CONFIG (7)
16+
#define UPDATE_ERROR_MAGIC_BYTE (8)
1617

1718

1819
#define U_FLASH 0

0 commit comments

Comments
 (0)