From 36609a8a7484ed0dcda2d5e7777a6380475c68a4 Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Fri, 19 Mar 2021 15:27:45 +0100 Subject: [PATCH] Fixes. --- Sming/Libraries/OtaUpgradeMqtt/component.mk | 5 ++++- .../samples/Upgrade/app/application.cpp | 2 +- .../Libraries/OtaUpgradeMqtt/src/PayloadParser.cpp | 13 +++++++++---- .../include/OtaUpgrade/Mqtt/RbootPayloadParser.h | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Sming/Libraries/OtaUpgradeMqtt/component.mk b/Sming/Libraries/OtaUpgradeMqtt/component.mk index 546a50cf15..8583388890 100644 --- a/Sming/Libraries/OtaUpgradeMqtt/component.mk +++ b/Sming/Libraries/OtaUpgradeMqtt/component.mk @@ -13,4 +13,7 @@ endif # If enabled (set to 1) then we can use unlimited number of patch versions COMPONENT_VARS += ENABLE_OTA_VARINT_VERSION -ENABLE_OTA_VARINT_VERSION ?= 1 \ No newline at end of file +ENABLE_OTA_VARINT_VERSION ?= 1 + +COMPONENT_CXXFLAGS := -DENABLE_OTA_ADVANCED=$(ENABLE_OTA_ADVANCED) \ + -DENABLE_OTA_VARINT_VERSION=$(ENABLE_OTA_VARINT_VERSION) \ No newline at end of file diff --git a/Sming/Libraries/OtaUpgradeMqtt/samples/Upgrade/app/application.cpp b/Sming/Libraries/OtaUpgradeMqtt/samples/Upgrade/app/application.cpp index f02f4928cb..708f7c4c10 100644 --- a/Sming/Libraries/OtaUpgradeMqtt/samples/Upgrade/app/application.cpp +++ b/Sming/Libraries/OtaUpgradeMqtt/samples/Upgrade/app/application.cpp @@ -62,7 +62,7 @@ void otaUpdate() #ifdef ENABLE_SSL mqtt.setSslInitHandler([](Ssl::Session& session) { // These fingerprints change very frequently. - static const Ssl::Fingerprint::Cert::Sha1 sha1Fingerprint PROGMEM = { MQTT_FINGERPRINT_SHA1 }; + static const Ssl::Fingerprint::Cert::Sha1 sha1Fingerprint PROGMEM = {MQTT_FINGERPRINT_SHA1}; // Trust certificate only if it matches the SHA1 fingerprint... session.validators.pin(sha1Fingerprint); diff --git a/Sming/Libraries/OtaUpgradeMqtt/src/PayloadParser.cpp b/Sming/Libraries/OtaUpgradeMqtt/src/PayloadParser.cpp index 7d754f65dc..b63a479ea5 100644 --- a/Sming/Libraries/OtaUpgradeMqtt/src/PayloadParser.cpp +++ b/Sming/Libraries/OtaUpgradeMqtt/src/PayloadParser.cpp @@ -18,7 +18,7 @@ namespace Mqtt { int PayloadParser::parse(MqttPayloadParserState& state, mqtt_message_t* message, const char* buffer, int length) { - if(message == nullptr || buffer == nullptr) { + if(message == nullptr) { debug_e("Invalid MQTT message"); return ERROR_INVALID_MQTT_MESSAGE; } @@ -46,16 +46,21 @@ int PayloadParser::parse(MqttPayloadParserState& state, mqtt_message_t* message, delete updateState->stream; delete updateState; if(success) { - debug_d("Swtiching was successful. Restarting..."); + debug_d("Switching was successful. Restarting..."); System.restart(); } else { - debug_e("Swtiching failed!"); + debug_e("Switching failed!"); } } return 0; } + if(buffer == nullptr) { + debug_e("Invalid MQTT message"); + return ERROR_INVALID_MQTT_MESSAGE; + } + if(!updateState->started) { size_t offset = 0; int patchVersion = getPatchVersion(buffer, length, offset, updateState->version); @@ -104,7 +109,7 @@ int PayloadParser::getPatchVersion(const char* buffer, int length, size_t& offse do { version += (buffer[offset] & 0x7f); useNextByte = (buffer[offset++] & 0x80); - } while(useNextByte && (offset < length)); + } while(useNextByte && (offset < size_t(length))); if(useNextByte) { // all the data is consumed and we still don't have a version number?! diff --git a/Sming/Libraries/OtaUpgradeMqtt/src/include/OtaUpgrade/Mqtt/RbootPayloadParser.h b/Sming/Libraries/OtaUpgradeMqtt/src/include/OtaUpgrade/Mqtt/RbootPayloadParser.h index bf44c5f34b..68e87dd53a 100644 --- a/Sming/Libraries/OtaUpgradeMqtt/src/include/OtaUpgrade/Mqtt/RbootPayloadParser.h +++ b/Sming/Libraries/OtaUpgradeMqtt/src/include/OtaUpgrade/Mqtt/RbootPayloadParser.h @@ -26,7 +26,8 @@ namespace Mqtt class RbootPayloadParser : public PayloadParser { public: - RbootPayloadParser(Storage::Partition part, size_t currentVersion) : PayloadParser(currentVersion), part(part) + RbootPayloadParser(Storage::Partition part, size_t currentVersion, size_t allowedVersionBytes = 24) + : PayloadParser(currentVersion, allowedVersionBytes), part(part) { }