Skip to content

MqttClient_Auth stalls indefinitely due to incorrect state transition check #442

Description

@kaabia

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 from MQTT_MSG_BEGIN to MQTT_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:

  1. Examine the MqttClient_Auth function's write logic after the header encoding phase.

  2. The code uses an incorrect conditional check: if (auth->stat.write == MQTT_MSG_BEGIN).

  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions