Skip to content

Gh issues - #615

Merged
aidangarske merged 18 commits into
wolfSSL:masterfrom
embhorn:gh_issues
Sep 11, 2026
Merged

aidangarske merged 18 commits into
wolfSSL:masterfrom
embhorn:gh_issues

Conversation

@embhorn

@embhorn embhorn commented Sep 8, 2026

Copy link
Copy Markdown
Member

@embhorn embhorn self-assigned this Sep 8, 2026
Copilot AI lite review requested due to automatic review settings September 8, 2026 16:42

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.

🟡 Changes recommended

There are remaining correctness issues in the new client-side state management (notably side effects on error paths and Packet Identifier release semantics) that can re-enable in-flight Packet Identifier reuse on an active connection.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR tightens MQTT 3.1.1/5.0 protocol conformance across the client and broker, addressing multiple reported issues around CONNECT sequencing, Packet Identifier lifetime, strict decoding, partial-write behavior, and WebSocket framing.

Changes:

  • Add explicit client handshake state (MQTT_CLIENT_FLAG_CONNECT_SENT) and enforce CONNECT-first / single-CONNECT-per-transport semantics across send APIs.
  • Add connection-level outbound Packet Identifier occupancy tracking to prevent reuse until the corresponding acknowledgement is processed.
  • Harden broker/client protocol handling (strict v3.1.1 CONNACK length, reject publish-response Packet Identifier 0, complete CONNACK delivery before closing, gate keepalive while CONNACK is pending, drop QoS0 after partial failure, enforce WebSocket binary frames), plus add regression tests.
File summaries
File Description
wolfmqtt/mqtt_client.h Introduces MQTT_CLIENT_FLAG_CONNECT_SENT and send_inflight/MQTT_MAX_SEND_INFLIGHT API/ABI surface changes.
wolfmqtt/mqtt_broker.h Adds connack_refused state to keep refused CONNACKs alive until fully written.
src/mqtt_socket.c Clears handshake flag on connect/disconnect to scope handshake state to the transport connection.
src/mqtt_packet.c Enforces v3.1.1 empty-ClientId+CleanSession rule, strict v3.1.1 CONNACK remaining length, and rejects publish-response Packet Identifier 0.
src/mqtt_client.c Implements CONNECT-first gating, CONNECT-once enforcement, send-inflight reservation/release, and ACK-driven Packet Identifier release.
src/mqtt_broker.c Enforces WebSocket binary-only frames; fixes CONNACK partial-write close timing; gates keepalive while CONNACK pending; fixes DUP/QoS0 replay corner cases.
examples/websocket/net_libwebsockets.c Closes WebSocket connection on non-binary frames per MQTT-over-WebSocket requirements.
tests/test_mqtt_props_init.c Adjusts ping test preconditions to reflect CONNECT-first gating.
tests/test_mqtt_packet.c Adds protocol regression tests for CONNACK length, CONNECT empty ClientId rule, and publish-response Packet Identifier validation.
tests/test_mqtt_client.c Adds client regression tests for CONNECT-first enforcement, CONNECT-once enforcement, and Packet Identifier occupancy behavior.
tests/test_broker_connect.c Adds broker regression tests covering refused/accepted CONNACK partial-write behavior, keepalive gating, and replay semantics.
ChangeLog.md Documents the behavioral changes and the fixed issues.
Review details

Suppressed comments (1)

src/mqtt_client.c:4504

  • MqttClient_CancelMessage unconditionally releases any reserved outbound Packet Identifier via MqttClient_SendIdReleaseOwner(). This makes it possible for application code to cancel an unacknowledged QoS>0 PUBLISH / SUBSCRIBE / UNSUBSCRIBE and then immediately reuse the same Packet Identifier on the same connection, which conflicts with the new in-flight Packet Identifier occupancy enforcement and the MQTT requirement that identifiers remain in use until the corresponding ACK is processed.
    /* Give back any outbound Packet Identifier this object reserved. Cancel is
     * the application saying it is done with the exchange and is reusing the
     * object, so the identifier must not stay claimed for the rest of the
     * connection - unlike the Receive Maximum unit below, a reused identifier
     * is the application's own call rather than a flow-control promise made to
     * the server. */
    MqttClient_SendIdReleaseOwner(client, msg);
  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mqtt_client.c

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot 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.

Fenrir Automated Review — PR #615

Scan targets checked: wolfmqtt-bugs, wolfmqtt-src

Findings: 6
6 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

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.

🟡 Changes recommended

The duplicate-CONNECT guard in MqttClient_Connect uses MqttClient_Flags(...,0,0) as a getter, which can return 0 on lockClient acquisition failure and incorrectly bypass the CONNECT-sent check under WOLFMQTT_MULTITHREAD.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 13/13 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/mqtt_client.c Outdated

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot 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.

Fenrir Automated Review — PR #615

Scan targets checked: wolfmqtt-src, wolfmqtt-bugs

Findings: 9
9 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread src/mqtt_client.c
Comment thread src/mqtt_client.c
Comment thread src/mqtt_client.c Outdated
Comment thread src/mqtt_client.c Outdated
Comment thread src/mqtt_client.c Outdated
Comment thread src/mqtt_client.c Outdated
Comment thread src/mqtt_client.c
Comment thread src/mqtt_client.c Outdated
Comment thread src/mqtt_client.c
@embhorn
embhorn requested a review from aidangarske September 10, 2026 15:50
@embhorn embhorn assigned aidangarske and unassigned embhorn Sep 10, 2026

@aidangarske aidangarske left a comment

Copy link
Copy Markdown
Member

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: 5 total — 5 posted, 0 skipped
5 finding(s) posted as inline comments (see file-level comments below)

Posted findings

  • [High] [review+review-security] Reject sends once the in-flight ID tracker is fullsrc/mqtt_client.c:854-865
  • [High] [review] Cancellation releases an identifier that may still be on the wiresrc/mqtt_client.c:5139-5145
  • [High] [review-security] ClientId hash collisions cross persistent-session statesrc/mqtt_client.c:509-521,3421-3492
  • [Medium] [review-security] Protocol DISCONNECT permits a second CONNECT on the same transportsrc/mqtt_client.c:4768-4775
  • [Medium] [review-security] Replay copies of application payloads are freed without zeroizationsrc/mqtt_client.c:604-615

Review generated by Skoll

Comment thread src/mqtt_client.c
Comment thread src/mqtt_client.c Outdated
Comment thread src/mqtt_client.c Outdated
Comment thread src/mqtt_client.c
Comment thread src/mqtt_client.c
@aidangarske aidangarske assigned embhorn and unassigned aidangarske Sep 10, 2026
@aidangarske

Copy link
Copy Markdown
Member

Do you want ChangeLog.md changes in there?

@embhorn

embhorn commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Do you want ChangeLog.md changes in there?

I think its fine. It will be useful going forward.

@aidangarske
aidangarske merged commit 3971244 into wolfSSL:master Sep 11, 2026
47 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

4 participants