add OTA file size sanity check

This commit is contained in:
technyon
2022-06-17 23:25:15 +02:00
parent efddec646d
commit 9e5388aee1
2 changed files with 9 additions and 3 deletions

10
Ota.cpp
View File

@@ -5,11 +5,17 @@
void Ota::updateFirmware(uint8_t* buf, size_t size)
{
if (!_updateFlag)
if(!_updateStarted && size == 0)
{
Serial.println("OTA upload cancelled, size is 0.");
return;
}
if (!_updateStarted)
{ //If it's the first packet of OTA since bootup, begin OTA
Serial.println("BeginOTA");
esp_ota_begin(esp_ota_get_next_update_partition(NULL), OTA_SIZE_UNKNOWN, &otaHandler);
_updateFlag = true;
_updateStarted = true;
}
esp_ota_write(otaHandler, buf, size);
if (size != FULL_PACKET)

2
Ota.h
View File

@@ -10,6 +10,6 @@ public:
void updateFirmware(uint8_t* buf, size_t size);
private:
bool _updateFlag = false;
bool _updateStarted = false;
esp_ota_handle_t otaHandler = 0;
};