Skip to content

Commit 02e6b2f

Browse files
committed
setMD5 has now returns bool
handle setMD5 failed in HTTP update reset UpdaterClass when MD5 check failed see: #1244
1 parent 727b6b1 commit 02e6b2f

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

cores/esp8266/Updater.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ bool UpdaterClass::begin(size_t size, int command) {
124124
return true;
125125
}
126126

127-
void UpdaterClass::setMD5(const char * expected_md5){
128-
if(strlen(expected_md5) != 32) return;
127+
bool UpdaterClass::setMD5(const char * expected_md5){
128+
if(strlen(expected_md5) != 32)
129+
{
130+
return false;
131+
}
129132
_target_md5 = expected_md5;
133+
return true;
130134
}
131135

132136
bool UpdaterClass::end(bool evenIfRemaining){
@@ -160,6 +164,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
160164
#ifdef DEBUG_UPDATER
161165
DEBUG_UPDATER.printf("MD5 Failed: expected:%s, calculated:%s\n", _target_md5.c_str(), _md5.toString().c_str());
162166
#endif
167+
_reset();
163168
return false;
164169
}
165170
#ifdef DEBUG_UPDATER

cores/esp8266/Updater.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class UpdaterClass {
6565
/*
6666
sets the expected MD5 for the firmware (hexString)
6767
*/
68-
void setMD5(const char * expected_md5);
68+
bool setMD5(const char * expected_md5);
6969

7070
/*
7171
returns the MD5 String of the sucessfully ended firmware

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,11 @@ bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int com
296296
}
297297

298298
if(md5.length()) {
299-
Update.setMD5(md5.c_str());
299+
if(!Update.setMD5(md5.c_str())) {
300+
lastError = HTTP_UE_SERVER_FAULTY_MD5;
301+
DEBUG_HTTP_UPDATE("[httpUpdate] Update.setMD5 failed! (%s)\n", md5.c_str());
302+
return false;
303+
}
300304
}
301305

302306
if(Update.writeStream(in) != size) {

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#define HTTP_UE_SERVER_FILE_NOT_FOUND (-102)
4545
#define HTTP_UE_SERVER_FORBIDDEN (-103)
4646
#define HTTP_UE_SERVER_WRONG_HTTP_CODE (-104)
47+
#define HTTP_UE_SERVER_FAULTY_MD5 (-105)
4748

4849
typedef enum {
4950
HTTP_UPDATE_FAILED,

0 commit comments

Comments
 (0)