espressif / ESP8266_RTOS_SDK

Latest ESP8266 SDK based on FreeRTOS, esp-idf style.
http://bbs.espressif.com
Apache License 2.0
3.35k stars 1.57k forks source link

fix(esp_https_ota): only do ota when http status code is 200 (GIT8266O-842) #1265

Open movsb opened 10 months ago

movsb commented 10 months ago

A status code of 404 (Not Found) returned from the OTA server causes the esp8266 to continue to write to the partition until it encounters an error of "OTA image has invalid magic byte (expected 0xE9, saw 0xXX)". This is somewhat ridiculous. HTTP StatusCode should be the first thing that we should do to check its content is right or not, not the Magic after reading some body. If the status code isn't OK, we should just simply drop the body (not read anything).

As for the code of esp-idf, it should also be better that we first check if the code is HttpStatus_OK, then any others. Processing non-OK HTTP error codes is sometimes optional. They exist for providing more debugging information (except for Redirections. Or maybe not, some implementations give us on option automatically do the redirections for us, not everybody who uses it).

https://github.com/espressif/esp-idf/blob/master/components/esp_https_ota/src/esp_https_ota.c#L93-L135

CLAassistant commented 10 months ago

CLA assistant check
All committers have signed the CLA.