Skip to content

Mqtt sn fixes#550

Draft
embhorn wants to merge 7 commits into
wolfSSL:masterfrom
embhorn:mqtt-sn-fixes
Draft

Mqtt sn fixes#550
embhorn wants to merge 7 commits into
wolfSSL:masterfrom
embhorn:mqtt-sn-fixes

Conversation

@embhorn
Copy link
Copy Markdown
Member

@embhorn embhorn commented Jun 2, 2026

  • Fixes from issues reported by user.
    Contribution provided by Javid (GitHub: jmestwa-coder)
  • Fix f-5501 MQTT-SN CONNACK
  • Fix f-3388 SN with MT & NB
  • Add tests for f-5864
  • Fix f-3137 harden SN_WillMessage

@embhorn embhorn self-assigned this Jun 2, 2026
Copilot AI review requested due to automatic review settings June 2, 2026 16:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens MQTT-SN packet handling (especially CONNACK) by adding stricter length/bounds validation in MQTT-SN decoders and ensuring the client path uses the dedicated CONNACK decoder instead of trusting the last byte. It also introduces a standalone unit test binary that regression-tests these decoder guards.

Changes:

  • Fix MQTT-SN CONNACK handling to decode/validate via SN_Decode_ConnectAck rather than reading rx_buf[buf_len-1].
  • Add additional declared-length lower-bound checks in SN_Decode_Header, SN_Decode_GWInfo, and SN_Decode_Register to prevent over-reads/underflows.
  • Add a new tests/test_mqtt_sn decoder-focused unit test program (wired into Automake) plus .gitignore entry.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_mqtt_sn.c New standalone unit tests that construct MQTT-SN frames to validate decoder bounds checks and CONNACK behavior.
tests/include.am Adds Automake rules to build/run the new tests/test_mqtt_sn program when BUILD_SN is enabled.
src/mqtt_sn_packet.c Adds missing lower-bound validation and corrects GWINFO address-length computation for IND vs short headers.
src/mqtt_sn_client.c Routes CONNACK handling through SN_Decode_ConnectAck for proper validation.
.gitignore Ignores the new tests/test_mqtt_sn test binary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_mqtt_sn.c
Comment on lines +249 to +251
/* [len=8][type=REGISTER][topicId=0x0102][packetId=0x0304]['a']['b'][\0] */
byte buf[9] = { 0x08, SN_MSG_TYPE_REGISTER, 0x01, 0x02, 0x03, 0x04,
'a', 'b', 0x00 };
Comment thread tests/test_mqtt_sn.c
Comment on lines +265 to +267
/* IND form: [IND][len=0x000A][type][topicId][packetId]['a']['b'][\0] */
byte buf[11] = { SN_PACKET_LEN_IND, 0x00, 0x0A, SN_MSG_TYPE_REGISTER,
0x01, 0x02, 0x03, 0x04, 'a', 'b', 0x00 };
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.

2 participants