From 50547d477cee1e25acf1505b8e01544909643aa5 Mon Sep 17 00:00:00 2001 From: Peter Jakobs Date: Fri, 25 Oct 2024 14:27:35 +0200 Subject: [PATCH 1/3] 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/3] 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/3] 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();