Skip to content

Stop outbound drain when Session hand-off takes its queue. Claim Will before publishing it. Do not report a successful cancel while a reader owns the request. Take the client lock over the Session replay pool in MqttClient_Connect. - #622

Open
kareem-wolfssl wants to merge 5 commits into
wolfSSL:masterfrom
kareem-wolfssl:zd22494

Conversation

@kareem-wolfssl

Copy link
Copy Markdown
Contributor

No description provided.

@kareem-wolfssl
kareem-wolfssl requested review from embhorn and a balanced review from Copilot September 24, 2026 23:29
@kareem-wolfssl kareem-wolfssl self-assigned this Sep 24, 2026

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.

Copilot review overview

🟡 Changes recommended

Build failure, replay races, non-terminating cancellation, and duplicate QoS 0 delivery remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 3 High severity · 1 Medium severity

Open (4)
What changed in this PR

Hardens MQTT client and broker state ownership during concurrent cancellation, session replay, queue hand-off, and Will publication.

Changes:

  • Adds synchronization and cancellation ownership safeguards.
  • Prevents broker queue and Will reuse during re-entrant callbacks.
  • Adds regression tests and allocator instrumentation.
File Description
wolfmqtt/​mqtt_client.h Documents cancellation ownership semantics.
src/​mqtt_client.c Synchronizes replay state and pending-response cancellation.
src/​mqtt_broker.c Handles re-entrant queue transfer and Will publication.
tests/​test_mqtt_client.c Tests replay locking and cancellation.
tests/​test_broker_connect.c Tests queue hand-off and Will re-entry.
tests/​include.am Injects allocator hooks into unit tests.

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

Comment thread src/mqtt_broker.c
Comment thread src/mqtt_client.c Outdated
Comment thread tests/include.am Outdated
Comment thread src/mqtt_client.c

@embhorn embhorn 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.

Review skoll comments and failing tests

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.

Comment thread src/mqtt_client.c
Comment on lines +820 to +823
if (client->replay[i].packet_id != 0 &&
MqttClient_SendIds_Find(client,
client->replay[i].packet_id) >= 0) {
continue; /* published on this connection */
Comment thread src/mqtt_client.c
Comment on lines +3688 to 3694
(void)MqttClient_SendIdReserve_Locked(client,
client->replay[i].packet_id, &client->replay[i], 1,
client->replay[i].pubrelSent ?
MQTT_PACKET_TYPE_PUBLISH_COMP :
((client->replay[i].qos == MQTT_QOS_2) ?
MQTT_PACKET_TYPE_PUBLISH_COMP :
MQTT_PACKET_TYPE_PUBLISH_ACK));
Comment thread src/mqtt_broker.c
Comment on lines +3526 to +3529
if (cur->qos != MQTT_QOS_0) {
cur->retransmit_dup = 1;
return;
}

@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 #622

Scan targets checked: wolfmqtt-src, wolfmqtt-bugs
Coverage: 2 of 5 in-scope changed file(s) opened by the reviewer; not opened: tests/test_broker_connect.c, tests/test_mqtt_client.c, wolfmqtt/mqtt_client.h

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

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

Review tier: Lite

Comment thread src/mqtt_client.c
tmpResp->packet_type, tmpResp->packet_id,
tmpResp->packetProcessing, tmpResp->packetDone);
#endif
if (tmpResp->packetProcessing && !tmpResp->packetDone) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New CONTINUE return from CancelMessage is ignored by internal error paths, leaving a stale pendResp linked · API contract violations

MqttClient_CancelMessage can now return MQTT_CODE_CONTINUE without unlinking the pendResp or resetting stat. The failure paths in Publish (4247, 4294), Subscribe (4543), Unsubscribe (4698), Ping (4862) and Connect (3457) ignore that return and report the error anyway. The caller can then free or reuse an object that is still on firstPendResp, which leaves a dangling list node.

Suggested fix: Update every internal caller of MqttClient_CancelMessage to handle MQTT_CODE_CONTINUE. Either wait until the reader sets packetDone and cancel again, or keep the object owned instead of returning an error.

Related known findings (similar but distinct; listed for context, not part of this finding)

  • F-13261 (open): File/function: same function MqttClient_CancelMessage as F-13261. Operation: F-13261 is the active-read release path omitting an rx_buf scrub; candidate is the packetProcessing-and-not-done early return skipping RespList_Remove when callers ignore MQTT_CODE_CONTINUE. Root cause: F-13261 is missing buffer zeroization (info disclosure); candidate is a missing caller-side contract check leaving a stale linked-list node (dangling pointer / potential use-after-free). Patch: one requires clearing rx_buf

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.

4 participants