From e88ff43dc57a3186ed7bd81ff241e3ee8d0c39ea Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 9 Aug 2023 09:50:10 +0200 Subject: [PATCH 1/4] Clear lzss static variables at download start --- src/decompress/lzss.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/decompress/lzss.cpp b/src/decompress/lzss.cpp index 72427ba..bce0e1c 100644 --- a/src/decompress/lzss.cpp +++ b/src/decompress/lzss.cpp @@ -30,6 +30,7 @@ int bit_buffer = 0, bit_mask = 128; unsigned char buffer[N * 2]; static size_t bytes_written_fputc = 0; +static size_t bytes_read_fgetc = 0; /************************************************************************************** PRIVATE FUNCTIONS @@ -45,8 +46,6 @@ void lzss_fputc(int const c) int lzss_fgetc() { - static size_t bytes_read_fgetc = 0; - /* lzss_file_size is set within SSUBoot:main * and contains the size of the LZSS file. Once * all those bytes have been read its time to return @@ -163,6 +162,8 @@ int lzss_download(ArduinoEsp32OtaReadByteFuncPointer read_byte, ArduinoEsp32OtaW read_byte_fptr = read_byte; write_byte_fptr = write_byte; LZSS_FILE_SIZE = lzss_file_size; + bytes_written_fputc = 0; + bytes_read_fgetc = 0; lzss_decode(); return bytes_written_fputc; } From 9c51acf37582e3e45fcbf0947ebf8730a7c5ffb9 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 16 Oct 2023 15:38:55 +0200 Subject: [PATCH 2/4] Initialize _ota variables inside begin function --- src/Arduino_ESP32_OTA.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Arduino_ESP32_OTA.cpp b/src/Arduino_ESP32_OTA.cpp index 9839e0a..a87cb3b 100644 --- a/src/Arduino_ESP32_OTA.cpp +++ b/src/Arduino_ESP32_OTA.cpp @@ -71,6 +71,10 @@ Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin() /* ... initialize CRC ... */ _crc32 = 0xFFFFFFFF; + + /* initialize private variables */ + _ota_size = 0; + _ota_header = {0}; if(!Update.begin(UPDATE_SIZE_UNKNOWN)) { DEBUG_ERROR("%s: failed to initialize flash update", __FUNCTION__); From a6eb0a8b64f136c622c926bc4f8a3da68c12599b Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 16 Aug 2023 11:38:46 +0200 Subject: [PATCH 3/4] Make sure _client is deleted returning from download function --- src/Arduino_ESP32_OTA.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Arduino_ESP32_OTA.cpp b/src/Arduino_ESP32_OTA.cpp index a87cb3b..f61ced1 100644 --- a/src/Arduino_ESP32_OTA.cpp +++ b/src/Arduino_ESP32_OTA.cpp @@ -146,6 +146,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url) if (!_client->connect(url.host_.c_str(), port)) { DEBUG_ERROR("%s: Connection failure with OTA storage server %s", __FUNCTION__, url.host_.c_str()); + delete _client; + _client = nullptr; return static_cast(Error::ServerConnectError); } @@ -176,6 +178,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url) if (!is_header_complete) { DEBUG_ERROR("%s: Error receiving HTTP header %s", __FUNCTION__, is_http_header_timeout ? "(timeout)":""); + delete _client; + _client = nullptr; return static_cast(Error::HttpHeaderError); } @@ -206,6 +210,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url) if (!content_length_ptr) { DEBUG_ERROR("%s: Failure to extract content length from http header", __FUNCTION__); + delete _client; + _client = nullptr; return static_cast(Error::ParseHttpHeader); } /* Find start of numerical value. */ @@ -233,17 +239,23 @@ int Arduino_ESP32_OTA::download(const char * ota_url) /* ... check for header download timeout ... */ if (is_ota_header_timeout) { + delete _client; + _client = nullptr; return static_cast(Error::OtaHeaderTimeout); } /* ... then check if OTA header length field matches HTTP content length... */ if (_ota_header.header.len != (content_length_val - sizeof(_ota_header.header.len) - sizeof(_ota_header.header.crc32))) { + delete _client; + _client = nullptr; return static_cast(Error::OtaHeaderLength); } /* ... and OTA magic number */ if (_ota_header.header.magic_number != ARDUINO_ESP32_OTA_MAGIC) { + delete _client; + _client = nullptr; return static_cast(Error::OtaHeaterMagicNumber); } @@ -255,9 +267,13 @@ int Arduino_ESP32_OTA::download(const char * ota_url) if(_ota_size <= content_length_val - sizeof(_ota_header)) { + delete _client; + _client = nullptr; return static_cast(Error::OtaDownload); } + delete _client; + _client = nullptr; return _ota_size; } From 8e67365f1a234d2fd95e463dc794efe58136ae02 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 16 Aug 2023 11:36:37 +0200 Subject: [PATCH 4/4] Check if an update process is up and running before begin a new one --- src/Arduino_ESP32_OTA.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Arduino_ESP32_OTA.cpp b/src/Arduino_ESP32_OTA.cpp index f61ced1..ebcd9f7 100644 --- a/src/Arduino_ESP32_OTA.cpp +++ b/src/Arduino_ESP32_OTA.cpp @@ -75,7 +75,12 @@ Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin() /* initialize private variables */ _ota_size = 0; _ota_header = {0}; - + + if(Update.isRunning()) { + Update.abort(); + DEBUG_DEBUG("%s: Aborting running update", __FUNCTION__); + } + if(!Update.begin(UPDATE_SIZE_UNKNOWN)) { DEBUG_ERROR("%s: failed to initialize flash update", __FUNCTION__); return Error::OtaStorageInit; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy