Skip to content

Conversation

@kaabia
Copy link
Contributor

@kaabia kaabia commented Nov 1, 2025

Fixes #442

Corrects a critical logic error in MqttClient_Auth where the function failed to check for the correct internal message state before attempting to send the AUTH packet payload over the network.

Problem

In MqttClient_Auth, the function transitions the write state from MQTT_MSG_BEGIN to MQTT_MSG_HEADER after encoding the fixed and
variable headers.

The subsequent block responsible for transmitting the packet incorrectly checked
if the state was still MQTT_MSG_BEGIN.

If the function was called again after the initial encoding, this logic error
would cause the AUTH packet to stall indefinitely because the state check
failed, preventing the wolfMqtt_Write call.

✅ Solution

The conditional check has been updated to look for the correct state, MQTT_MSG_HEADER, which is the state required to start the network
transmission phase.

Code Change Detail:

// Before:
if (auth->stat.write == MQTT_MSG_BEGIN) {
// After:
if (auth->stat.write == MQTT_MSG_HEADER) {

This ensures the AUTH packet is correctly picked up and sent upon subsequent
calls, resolving the potential stall in the authentication flow.

@wolfSSL-Bot
Copy link

Can one of the admins verify this patch?

@embhorn
Copy link
Member

embhorn commented Nov 5, 2025

HI @kaabia

Please see the note I left in your other PR:
#440 (comment)

@kaabia
Copy link
Contributor Author

kaabia commented Nov 5, 2025

HI @kaabia

Please see the note I left in your other PR: #440 (comment)

Hello @embhorn, I can confirm the signed contributor agreement has been sent back to [email protected]

Thank you for your review. I also want to mention that the test gate is currently failing due to expired certificates that need updating in the test suite:

[2025/11/01 15:42:37:6708] E: SSL error: **certificate has expired** (preverify_ok=0;err=10;depth=1)

This indicates that the failure is related to expired test assets, not the code change itself.

Thank you!

@embhorn
Copy link
Member

embhorn commented Nov 6, 2025

Hi @kaabia

Please rebase and push to restart the tests with the test fixes in place.

@embhorn embhorn assigned kaabia and unassigned embhorn Nov 6, 2025
@kaabia kaabia force-pushed the fix/auth-state-check branch from 09cd867 to ece0a77 Compare November 6, 2025 21:07
@kaabia
Copy link
Contributor Author

kaabia commented Nov 6, 2025

Hi @kaabia

Please rebase and push to restart the tests with the test fixes in place.

Hi @embhorn
Done as well

Fixes an issue in MqttClient_Auth where the logic failed to check for the
correct message state before packet transmission.

The 'Auth' write state transitions from MQTT_MSG_BEGIN to MQTT_MSG_HEADER
after initial encoding. However, the subsequent conditional check was
erroneously looking for MQTT_MSG_BEGIN.

This logic error could cause the AUTH packet to stall if the function was
called repeatedly, especially in a multithreaded context.

This change updates the check to correctly look for the MQTT_MSG_HEADER
state, ensuring the AUTH packet is reliably sent over the network.

Signed-off-by: Badr Bacem KAABIA <[email protected]>
@kaabia kaabia force-pushed the fix/auth-state-check branch from ece0a77 to 2e87475 Compare November 7, 2025 18:44
@kaabia kaabia requested a review from embhorn November 7, 2025 18:45
@embhorn embhorn merged commit 49d5265 into wolfSSL:master Nov 7, 2025
12 of 13 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.

MqttClient_Auth stalls indefinitely due to incorrect state transition check

3 participants