Skip to content

Fix broker disconnect to better handle SIGPIPE#548

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:broker_dis
Open

Fix broker disconnect to better handle SIGPIPE#548
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:broker_dis

Conversation

@dgarske
Copy link
Copy Markdown
Member

@dgarske dgarske commented May 27, 2026

No description provided.

@dgarske dgarske self-assigned this May 27, 2026
@dgarske dgarske requested a review from embhorn May 28, 2026 00:24
@dgarske dgarske assigned embhorn and unassigned dgarske May 28, 2026
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 #548

Scan targets checked: wolfmqtt-bugs, wolfmqtt-src

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

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread src/mqtt_broker.c
#ifdef MSG_NOSIGNAL
rc = (int)send(sock, buf, (size_t)buf_len, MSG_NOSIGNAL);
#else
rc = (int)send(sock, buf, (size_t)buf_len, 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 [Medium] Fallback write path still allows SIGPIPE · Logic errors

BrokerPosix_Write falls back to plain send(..., 0) when neither MSG_NOSIGNAL nor SO_NOSIGPIPE is available, so public POSIX-backend users outside wolfmqtt_broker() still take the original SIGPIPE termination path.

Fix: Add a fallback SIGPIPE suppression path or fail initialization when no per-send or per-socket suppression is available.

* after PUBREC. The strong assertion is that ASan finds no UAF when we
* tear down the broker while the publisher is still in qos2_pending. */
mc = &g_clients[1];
mc->closed = 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 [Low] Abrupt-close test never exercises abnormal close · Weak or missing assertions

mc->closed = 1 makes mock_read() return MQTT_CODE_ERROR_TIMEOUT, and BrokerClient_Process() treats that as idle, so this test never exercises the abnormal-close branch it is meant to cover.

Fix: Make the mock return MQTT_CODE_ERROR_NETWORK for this case and assert the publisher client is removed or closed.

Comment thread src/mqtt_broker.c
* publishes QoS>0 and immediately closes its socket would cause the
* broker's PUBACK/PUBREC write to deliver SIGPIPE, terminating the
* broker. Linux uses MSG_NOSIGNAL in BrokerPosix_Write instead. */
(void)setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 [Low] SIGPIPE suppression can silently remain disabled · Resource leaks

BrokerPosix_Accept ignores SO_NOSIGPIPE setup failure, so accepted sockets can still reach the zero-flag send() path and let a peer-closed write terminate the broker with SIGPIPE.

Fix: Check setsockopt and reject the accepted socket, or install a backend fallback before returning success.

@embhorn embhorn assigned dgarske and unassigned embhorn May 29, 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.

3 participants