From 50547d477cee1e25acf1505b8e01544909643aa5 Mon Sep 17 00:00:00 2001 From: Peter Jakobs Date: Fri, 25 Oct 2024 14:27:35 +0200 Subject: [PATCH 1/5] catch situations where mqttClient::connect is called with an empty clientName that would otherwise lead to a failing malloc --- Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp index be7e8896a7..cb2b77d28f 100644 --- a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp +++ b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp @@ -199,11 +199,17 @@ bool MqttClient::setWill(const String& topic, const String& message, uint8_t fla bool MqttClient::connect(const Url& url, const String& clientName) { this->url = url; + bool useSsl{url.Scheme == URI_SCHEME_MQTT_SECURE}; if(!useSsl && url.Scheme != URI_SCHEME_MQTT) { debug_e("Only mqtt and mqtts protocols are allowed"); return false; } + if(clientName==""){ + debug_e("no client name configured"); + return false; + } + if(getConnectionState() != eTCS_Ready) { close(); From f4453c4b8193eb0df387accf3bd13cfa1cb72c10 Mon Sep 17 00:00:00 2001 From: Peter Jakobs Date: Fri, 25 Oct 2024 14:39:30 +0200 Subject: [PATCH 2/5] made error message a bit clearer --- Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp index cb2b77d28f..500b9e508e 100644 --- a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp +++ b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp @@ -206,7 +206,7 @@ bool MqttClient::connect(const Url& url, const String& clientName) return false; } if(clientName==""){ - debug_e("no client name configured"); + debug_e("clientName cannot be empty"); return false; } From 43dddb26fa4b2a0da6667ba2a0ebbc31e9e3a259 Mon Sep 17 00:00:00 2001 From: Peter Jakobs Date: Sun, 27 Oct 2024 21:42:31 +0100 Subject: [PATCH 3/5] fixed spaces to tabs --- .../Components/Network/src/Network/Mqtt/MqttClient.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp index 500b9e508e..a1963b3b83 100644 --- a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp +++ b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp @@ -205,11 +205,11 @@ bool MqttClient::connect(const Url& url, const String& clientName) debug_e("Only mqtt and mqtts protocols are allowed"); return false; } - if(clientName==""){ - debug_e("clientName cannot be empty"); - return false; - } - + + if(clientName==""){ + debug_e("clientName cannot be empty"); + return false; + } if(getConnectionState() != eTCS_Ready) { close(); From cc75f4416cb04dbbee0441e057de7e7fc69072f9 Mon Sep 17 00:00:00 2001 From: Peter Jakobs Date: Mon, 28 Oct 2024 11:15:17 +0100 Subject: [PATCH 4/5] Catch situations where mqttClient::connect is called with an empty clientName. --- Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp index a1963b3b83..dd00284d2d 100644 --- a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp +++ b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp @@ -205,6 +205,10 @@ bool MqttClient::connect(const Url& url, const String& clientName) debug_e("Only mqtt and mqtts protocols are allowed"); return false; } + if(clientName == "") { + debug_e("clientName cannot be empty"); + return false; + } if(clientName==""){ debug_e("clientName cannot be empty"); From a52ffaec6a7388aeef48fbce5135959547a18841 Mon Sep 17 00:00:00 2001 From: Peter Jakobs Date: Wed, 30 Oct 2024 17:25:18 +0100 Subject: [PATCH 5/5] moved the implementation of 'getMaxDuty()' into the cpp file for all architectures. Before, for esp32c3, the function in header would always return 0. --- Sming/Arch/Esp32/Core/HardwarePWM.cpp | 5 +++++ Sming/Arch/Esp8266/Core/HardwarePWM.cpp | 5 +++++ Sming/Arch/Host/Core/HardwarePWM.cpp | 5 +++++ Sming/Arch/Rp2040/Core/HardwarePWM.cpp.todo | 5 +++++ Sming/Core/HardwarePWM.h | 5 +---- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Sming/Arch/Esp32/Core/HardwarePWM.cpp b/Sming/Arch/Esp32/Core/HardwarePWM.cpp index fcc387dc34..89d785acb3 100644 --- a/Sming/Arch/Esp32/Core/HardwarePWM.cpp +++ b/Sming/Arch/Esp32/Core/HardwarePWM.cpp @@ -223,6 +223,11 @@ uint32_t HardwarePWM::getDutyChan(uint8_t chan) return (chan == PWM_BAD_CHANNEL) ? 0 : ledc_get_duty(pinToGroup(chan), pinToChannel(chan)); } +uint32_t HardwarePWM::getMaxDuty() +{ + return maxduty; +} + bool HardwarePWM::setDutyChan(uint8_t chan, uint32_t duty, bool update) { if(chan == PWM_BAD_CHANNEL) { diff --git a/Sming/Arch/Esp8266/Core/HardwarePWM.cpp b/Sming/Arch/Esp8266/Core/HardwarePWM.cpp index 1483df469e..1eb9925b7f 100644 --- a/Sming/Arch/Esp8266/Core/HardwarePWM.cpp +++ b/Sming/Arch/Esp8266/Core/HardwarePWM.cpp @@ -125,6 +125,11 @@ uint32_t HardwarePWM::getPeriod() return pwm_get_period(); } +uint32_t getMaxDuty() +{ + return maxduty; +} + void HardwarePWM::setPeriod(uint32_t period) { maxduty = PERIOD_TO_MAX_DUTY(period); diff --git a/Sming/Arch/Host/Core/HardwarePWM.cpp b/Sming/Arch/Host/Core/HardwarePWM.cpp index cf5d2de430..6846f9dccf 100644 --- a/Sming/Arch/Host/Core/HardwarePWM.cpp +++ b/Sming/Arch/Host/Core/HardwarePWM.cpp @@ -46,6 +46,11 @@ bool HardwarePWM::setDutyChan(uint8_t chan, uint32_t duty, bool update) return false; } +uint32_t HardwarePWM::getMaxDuty() +{ + return 0; +} + uint32_t HardwarePWM::getPeriod() { return 0; diff --git a/Sming/Arch/Rp2040/Core/HardwarePWM.cpp.todo b/Sming/Arch/Rp2040/Core/HardwarePWM.cpp.todo index 6def2d36fd..2c71ef6f49 100644 --- a/Sming/Arch/Rp2040/Core/HardwarePWM.cpp.todo +++ b/Sming/Arch/Rp2040/Core/HardwarePWM.cpp.todo @@ -116,6 +116,11 @@ uint32 HardwarePWM::getPeriod() return pwm_get_period(); } +uint32_t HardwarePWM::getMaxDuty() +{ + return maxduty; +} + /* Function Name: setPeriod * Description: This function is used to set Period of PWM. * Period / frequency will remain same for all pins. diff --git a/Sming/Core/HardwarePWM.h b/Sming/Core/HardwarePWM.h index fe1d6d501d..9d529633ec 100644 --- a/Sming/Core/HardwarePWM.h +++ b/Sming/Core/HardwarePWM.h @@ -113,10 +113,7 @@ class HardwarePWM * @retval uint32_t Maximum permissible duty cycle * @note Attempt to set duty of a pin above this value will fail */ - uint32_t getMaxDuty() - { - return maxduty; - } + uint32_t getMaxDuty(); /** @brief This function is used to actually update the PWM. */