-
Notifications
You must be signed in to change notification settings - Fork 167
MqttClient_Auth stalls indefinitely due to incorrect state transition check #442
Description
Describe the bug
This issue reports a critical logic error in the MqttClient_Auth function that could cause the AUTH packet transmission to stall indefinitely under specific conditions, preventing successful client authentication.
-
Logic Flaw: In
MqttClient_Auth, after the fixed and variable headers are successfully encoded, the write state is correctly transitioned fromMQTT_MSG_BEGINtoMQTT_MSG_HEADER. -
Incorrect Check: The subsequent code block responsible for sending the packet payload erroneously checked if the state was still
MQTT_MSG_BEGIN. -
Impact: If the function was called repeatedly (common in non-blocking environments), the state check would immediately fail (
MQTT_MSG_HEADER != MQTT_MSG_BEGIN), preventing the network write call (wolfMqtt_Write) from being executed. This causes the AUTH packet to stall, halting the authentication flow.
Area: Client, Authentication, State Machine
Steps to reproduce
The bug is a logic error in the state machine transition check.
Write:
Examine the
MqttClient_Authfunction's write logic after the header encoding phase.The code uses an incorrect conditional check:
if (auth->stat.write == MQTT_MSG_BEGIN).The check should instead be
if (auth->stat.write == MQTT_MSG_HEADER)to correctly pick up the packet for network transmission after the initial header encoding.
Additional Context
Fix Proposal is presented in the following PR: #439