Skip to content

Reject null chars in strings#503

Merged
dgarske merged 2 commits intowolfSSL:masterfrom
embhorn:zd21729
May 5, 2026
Merged

Reject null chars in strings#503
dgarske merged 2 commits intowolfSSL:masterfrom
embhorn:zd21729

Conversation

@embhorn
Copy link
Copy Markdown
Member

@embhorn embhorn commented Apr 30, 2026

MQTT 3.1.1 explicitly requires receivers to close the network connection when a Control Packet contains U+0000 in a UTF-8 encoded string.

Credit for reporting this issue:
Xiangdong Li (Student, Beijing University of Posts and Telecommunicationsp[BUPT])

Added tests

decode_publish_rejects_nul_in_topic
decode_connect_rejects_nul_in_client_id
decode_connect_rejects_nul_in_username
decode_connect_rejects_nul_in_password
decode_connect_rejects_nul_in_will_topic
decode_subscribe_rejects_nul_in_filter
decode_publish_v5_rejects_nul_in_string_property
decode_unsubscribe_rejects_nul_in_filter

Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #503

Scan targets checked: wolfmqtt-bugs, wolfmqtt-src

No new issues found in the changed files. ✅

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 wolfMQTT’s packet decoding to reject embedded NUL bytes (U+0000 / 0x00) in MQTT UTF-8 strings, aligning with MQTT 3.1.1/5.0 requirements and preventing downstream C-string truncation issues in broker logic.

Changes:

  • Add an embedded-NUL rejection check to MqttDecode_String, returning MQTT_CODE_ERROR_MALFORMED_DATA.
  • Propagate underlying MqttDecode_String errors through MqttDecode_Publish and MQTT v5 property string decoding (MqttDecode_Props) rather than masking them.
  • Add targeted decode tests covering topic names/filters, CONNECT fields, and v5 string properties; add XMEMCHR portability macro.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
wolfmqtt/mqtt_types.h Adds XMEMCHR wrapper (defaults to memchr) to support the new NUL-scan in decoding.
src/mqtt_packet.c Rejects embedded NULs in MqttDecode_String and propagates string decode errors from PUBLISH + v5 property parsing.
tests/test_mqtt_packet.c Adds regression tests ensuring decode paths reject NULs in topic/client-id/credentials/filters and v5 string properties.
src/mqtt_broker.c Updates internal documentation to reflect the new “no embedded NUL” invariant for protocol-decoded strings.
ChangeLog.md Documents the behavior/API changes for the pending release.

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

Comment thread ChangeLog.md Outdated
@embhorn embhorn requested a review from aidangarske April 30, 2026 20:37
@embhorn embhorn assigned aidangarske and unassigned embhorn Apr 30, 2026
Copy link
Copy Markdown
Member

@aidangarske aidangarske left a comment

Choose a reason for hiding this comment

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

Skoll Multi-Scan Review

Modes: review + review-security
Overall recommendation: REQUEST_CHANGES
Findings: 7 total — 7 posted, 0 skipped
7 finding(s) posted as inline comments (see file-level comments below)

Posted findings

  • [High] [review+review-security] CONNECT password path now rejects valid binary payloads containing 0x00src/mqtt_packet.c:350-362
  • [Medium] [review] v5 string-property NUL test gated behind WOLFMQTT_BROKERtests/test_mqtt_packet.c:1735-1753, 2374
  • [Medium] [review] STRING_PAIR error-propagation branch in MqttDecode_Props has no direct regression testsrc/mqtt_packet.c:717-755
  • [Medium] [review] Behavior change in MqttDecode_Props error code is a soft API break for property decode callerssrc/mqtt_packet.c:645-668, 713-755
  • [Low] [review-security] New XMEMCHR usage breaks WOLFMQTT_CUSTOM_STRING buildswolfmqtt/mqtt_types.h:222-251
  • [Low] [review] Test placed under MqttDecode_Subscribe section but tests PUBLISHtests/test_mqtt_packet.c:1735-1753
  • [Low] [review] Comment in mqtt_broker.c overstates the invariant guaranteesrc/mqtt_broker.c:177-188

Review generated by Skoll

Comment thread src/mqtt_packet.c
Comment thread tests/test_mqtt_packet.c
Comment thread src/mqtt_packet.c
Comment thread wolfmqtt/mqtt_types.h Outdated
Comment thread tests/test_mqtt_packet.c Outdated
Comment thread src/mqtt_broker.c
Comment thread src/mqtt_packet.c
@embhorn embhorn requested a review from wolfSSL-Fenrir-bot May 1, 2026 18:07
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #503

Scan targets checked: wolfmqtt-bugs, wolfmqtt-src

No new issues found in the changed files. ✅

@embhorn embhorn requested a review from aidangarske May 1, 2026 19:04
@embhorn embhorn assigned wolfSSL-Bot and unassigned aidangarske May 5, 2026
@dgarske dgarske merged commit 1656a91 into wolfSSL:master May 5, 2026
36 checks passed
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.

6 participants