Skip to content

"magic numbers" for MQTT topic buffer length in mqtt.cpp and button.cpp (use already defined MQTT_MAX_TOPIC_LEN) #4293

Closed

Description

@WouterGritter

What happened?

I was modifying the source code on a fork for my custom MQTT topic structure and noticed MQTT_MAX_TOPIC_LEN is not used in all places the associated variables mqttDeviceTopic and mqttGroupTopic are used.

When increasing this defined variable, buffer overflows will occur when trying to generate topics to publish on in mqtt.cpp and button.cpp. I personally organize all MQTT devices in a <building>/<room>/<device> topic structure, and this could potentially be more than the current 32 max topic length.

Currently, when trying to increase this variable, the following things need to be changed:

  • MQTT_MAX_TOPIC_LEN
  • lots of buffer allocation code in mqtt.cpp and button.cpp
  • maxlength attribute on <input> elements in settings_sync.html

It's bug-prone to have to manually adjust the buffer sizes in both cpp files. However it might be nice to have to also automatically populate the maxlength attribute on the <input> element. Not sure if this easy though.


Not applicable headers removed.

What version of WLED?

0.15.0-b7

Anything else?

If no one else is one this after a while I'll try to submit a PR myself. Bare with me if I do that, because I've never contributed to open source before!

I'm submitting a PR for the fix.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. WouterGritter commented on Nov 20, 2024

    @WouterGritter
    ContributorAuthor

    Opened a PR for this.

  2. WouterGritter commented on Nov 21, 2024

    @WouterGritter
    ContributorAuthor

    !4295 uses MQTT_MAX_TOPIC_LEN to allocate topic string buffers.

    Currently, when trying to increase this variable, the following things need to be changed:

    • maxlength attribute on <input> elements in settings_sync.html

    This was already implemented but the feature was broken. !4296 fixes this.

  3. added
    fixed in source
    on Nov 21, 2024
  4. blazoncek commented on Nov 21, 2024

    @blazoncek
    Contributor

    You can close this now.

  5. WouterGritter commented on Nov 22, 2024

    @WouterGritter
    ContributorAuthor

    !4295 (the one that fixes magic numbers) is still open. Two PRs were spawned from this issue.

  6. removed
    fixed in source
    on Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions