Mqtt sn fixes#550
Draft
embhorn wants to merge 7 commits into
Draft
Conversation
There was a problem hiding this comment.
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_ConnectAckrather than readingrx_buf[buf_len-1]. - Add additional declared-length lower-bound checks in
SN_Decode_Header,SN_Decode_GWInfo, andSN_Decode_Registerto prevent over-reads/underflows. - Add a new
tests/test_mqtt_sndecoder-focused unit test program (wired into Automake) plus.gitignoreentry.
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 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 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 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution provided by Javid (GitHub: jmestwa-coder)