From 53e01932d3743850fddaddcb4969dff585db92ff Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sun, 20 Dec 2015 11:46:00 +0100 Subject: [PATCH] add magic byte check for Update class Note: only check of first 0xE9 possible. --- cores/esp8266/Updater.cpp | 12 ++++++++++++ cores/esp8266/Updater.h | 1 + 2 files changed, 13 insertions(+) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index 3266266c7..c890a13af 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -252,6 +252,16 @@ size_t UpdaterClass::writeStream(Stream &data) { if(hasError() || !isRunning()) return 0; + // check for valid first magic byte (is always 0xE9) + if(data.peek() != 0xE9) { + _error = UPDATE_ERROR_MAGIC_BYTE; + _currentAddress = (_startAddress + _size); +#ifdef DEBUG_UPDATER + printError(DEBUG_UPDATER); +#endif + return 0; + } + while(remaining()) { toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen)); if(toRead == 0) { //Timeout @@ -293,6 +303,8 @@ void UpdaterClass::printError(Stream &out){ out.println("MD5 Check Failed"); } else if(_error == UPDATE_ERROR_FLASH_CONFIG){ out.printf("Flash config wrong real: %d IDE: %d\n", ESP.getFlashChipRealSize(), ESP.getFlashChipSize()); + } else if(_error == UPDATE_ERROR_MAGIC_BYTE){ + out.println("Magic byte is wrong, not 0xE9"); } else { out.println("UNKNOWN"); } diff --git a/cores/esp8266/Updater.h b/cores/esp8266/Updater.h index 58d7aa19e..94ea3b241 100644 --- a/cores/esp8266/Updater.h +++ b/cores/esp8266/Updater.h @@ -13,6 +13,7 @@ #define UPDATE_ERROR_STREAM (5) #define UPDATE_ERROR_MD5 (6) #define UPDATE_ERROR_FLASH_CONFIG (7) +#define UPDATE_ERROR_MAGIC_BYTE (8) #define U_FLASH 0