Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update mqttClient to catch empty clientNames #2897

Closed
wants to merge 4 commits into from

Conversation

pljakobs
Copy link
Contributor

catch situations where mqttClient::connect is called with an empty clientName that would otherwise lead to a failing malloc

…ientName that would otherwise lead to a failing malloc
Copy link

what-the-diff bot commented Oct 25, 2024

PR Summary

  • Enhanced Validation for Client Name
    This update adds a safeguard in the 'connect' operation. If someone tries to initiate a connection without specifying who they are (the client name), the system will catch this oversight and log an error message. This ensures that all connections have proper identification, which improves tracking and troubleshooting.

@slaff
Copy link
Contributor

slaff commented Oct 27, 2024

@pljakobs make sure to fix the coding style.

@pljakobs
Copy link
Contributor Author

pljakobs commented Oct 27, 2024

@pljakobs make sure to fix the coding style.

when I run "make cs" in $SMING_HOME, I get a huge changeset with all sorts of files that I didn't touch but my four lines look unchanged - I think the way cs is set up right now, it wants to change the tab size across the whole project. I would rather not submit that large a change.

diff --git a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp
index be7e8896..0d9bd1bc 100644
--- a/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp
+++ b/Sming/Components/Network/src/Network/Mqtt/MqttClient.cpp
@@ -199,11 +199,16 @@ 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("clientName cannot be empty");
+               return false;
+       }
 
        if(getConnectionState() != eTCS_Ready) {
                close();

If I use eight character indents on those four lines alone they stick out like a sore thumb.

for completeness: this is the beginning of the full git diff after running make cs:

diff --git a/Sming/Arch/Esp32/Components/driver/include/driver/hw_timer.h b/Sming/Arch/Esp32/Components/driver/include/driver/hw_timer.h
index 1979b450..af4692cf 100644
--- a/Sming/Arch/Esp32/Components/driver/include/driver/hw_timer.h
+++ b/Sming/Arch/Esp32/Components/driver/include/driver/hw_timer.h
@@ -75,7 +75,7 @@ typedef enum {
 } hw_timer_clkdiv_t;
 
 typedef enum {
-       TIMER_EDGE_INT = 0,  // edge interrupt
+       TIMER_EDGE_INT = 0,      // edge interrupt
        TIMER_LEVEL_INT = 1, // level interrupt
 } hw_timer_intr_type_t;
 
diff --git a/Sming/Arch/Esp8266/Core/Digital.cpp b/Sming/Arch/Esp8266/Core/Digital.cpp
index 7a7af26d..42ddf91d 100644
--- a/Sming/Arch/Esp8266/Core/Digital.cpp
+++ b/Sming/Arch/Esp8266/Core/Digital.cpp
@@ -16,26 +16,26 @@
 
 #define TOTAL_PINS 16
 
-#define PINMUX_OFFSET(addr) uint8_t((addr)-PERIPHS_IO_MUX)
+#define PINMUX_OFFSET(addr) uint8_t((addr) - PERIPHS_IO_MUX)
 
 // Used for pullup/noPullup
 extern const uint8_t esp8266_pinmuxOffset[] = {
-       PINMUX_OFFSET(PERIPHS_IO_MUX_GPIO0_U),  // 0 FLASH
-       PINMUX_OFFSET(PERIPHS_IO_MUX_U0TXD_U),  // 1 TXD0
-       PINMUX_OFFSET(PERIPHS_IO_MUX_GPIO2_U),  // 2 TXD1
-       PINMUX_OFFSET(PERIPHS_IO_MUX_U0RXD_U),  // 3 RXD0
-       PINMUX_OFFSET(PERIPHS_IO_MUX_GPIO4_U),  // 4
-       PINMUX_OFFSET(PERIPHS_IO_MUX_GPIO5_U),  // 5
-       PINMUX_OFFSET(PERIPHS_IO_MUX_SD_CLK_U),   // 6 SD_CLK_U
+       PINMUX_OFFSET(PERIPHS_IO_MUX_GPIO0_U),    // 0 FLASH
+       PINMUX_OFFSET(PERIPHS_IO_MUX_U0TXD_U),    // 1 TXD0
+       PINMUX_OFFSET(PERIPHS_IO_MUX_GPIO2_U),    // 2 TXD1
+       PINMUX_OFFSET(PERIPHS_IO_MUX_U0RXD_U),    // 3 RXD0
+       PINMUX_OFFSET(PERIPHS_IO_MUX_GPIO4_U),    // 4
+       PINMUX_OFFSET(PERIPHS_IO_MUX_GPIO5_U),    // 5
+       PINMUX_OFFSET(PERIPHS_IO_MUX_SD_CLK_U),   // 6 SD_CLK_U
        PINMUX_OFFSET(PERIPHS_IO_MUX_SD_DATA0_U), // 7 SD_DATA0_U
        PINMUX_OFFSET(PERIPHS_IO_MUX_SD_DATA1_U), // 8 SD_DATA1_U

the changes seem all to be coding style related.

@mikee47
Copy link
Contributor

mikee47 commented Oct 27, 2024

Needs to be clang-format version 8, I suspect you're running a more recent version...

@mikee47
Copy link
Contributor

mikee47 commented Oct 27, 2024

It's also a good idea to create a new branch for PR's (i.e. don't use develop directly). See https://sming.readthedocs.io/en/latest/_inc/CONTRIBUTING.html

@pljakobs
Copy link
Contributor Author

Needs to be clang-format version 8, I suspect you're running a more recent version...

clang-format --version
clang-format version 18.1.8 (Fedora 18.1.8-1.fc40)

that's a lot more more than 8 than I would have guessed - am I missing something?

It's also a good idea to create a new branch for PR's (i.e. don't use develop directly). See https://sming.readthedocs.io/en/latest/_inc/CONTRIBUTING.html

I know, and usually I try to.

@mikee47
Copy link
Contributor

mikee47 commented Oct 28, 2024

The issues with differing versions of clang-format is a widely discussed issue. You can find a standalone version here https://github.com/muttleyxd/clang-tools-static-binaries

@mikee47
Copy link
Contributor

mikee47 commented Oct 28, 2024

CLANG_FORMAT=clang-format-8 make cs

@pljakobs pljakobs closed this Oct 28, 2024
@pljakobs
Copy link
Contributor Author

pljakobs commented Oct 28, 2024

CLANG_FORMAT=clang-format-8 make cs

~~really? it would have been that easy? :o ~~

would that not be something to add the the makefile then?

I misread this, I thought it was a format modifier, but this just sets the static clang-format executable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants