Skip to content

MQTT-SN fixes#550

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

MQTT-SN fixes#550
embhorn wants to merge 21 commits into
wolfSSL:masterfrom
embhorn:mqtt-sn-fixes

Conversation

@embhorn

@embhorn embhorn commented Jun 2, 2026

Copy link
Copy Markdown
Member
  • 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
  • Fix f-3138 harden SN_Client_WillMsgUpdate
  • Fix f-2756 SN_Client_Subscribe false return code
  • Fix f-3132 SN_Client_Ping with null
  • Fix f-4518 SN_Client_HandlePacket type issue in debug
  • Fix f-5510: MQTT-SN publish encoder harden
  • Fix f-4659: topic_type check in SN_Decode_Publish
  • Fix f-4248: SN_Decode_Publish validate packet_id with QoS>0
  • Fix f-2332: SN_Encode_Subscribe/Unsubscribe check topicNameId
  • Fix f-4058: SN_Decode_Header check buf_len
  • Fix f-3632: Add tests for SN_Decode_GWInfo
  • Fix f-2333 and f-2334: SN_Encode_WillTopic/Update check willTopic
  • Fix f-2330: SN_Encode_Register check topicName
  • Fix f-3831: SN_Decode_Register bounds check rejects all valid REGISTER packets
  • Fix f-5663: example use of sn_reg_callback
  • Fix f-5664: Check payload in sn_message_cb
  • Fix f-5146: publish task testing

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

Copilot AI left a comment

Copy link
Copy Markdown

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 };
@embhorn embhorn changed the title Mqtt sn fixes MQTT-SN fixes Jun 9, 2026
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