Skip to content

mqtt: acknowledgement with an unknown packet id causes a null dereference #3165

Closed

Description

@jfallows

Problem

An inbound PUBACK, PUBREC, PUBCOMP or PUBREL whose packet id the server has no state for dereferences a null (line numbers on develop at b1a53e9, approximate):

  • PUBACK, PUBREC and PUBCOMP in MqttServerFactory (~3847-3896);
  • PUBREL in MqttKafkaSessionFactory (~822-826).

A client that retransmits PUBREL after a lost PUBCOMP, or a client that acknowledges a packet id the server no longer tracks (for example after a reconnect), triggers it.

MQTT 5.0 sections 3.6.2.1 (PUBREL) and 3.7.2.1 (PUBCOMP): reason code 0x92 (Packet Identifier not found) exists for the case where the receiver has no state for the packet id. MQTT 3.1.1 section 4.3.3 has the receiver answer PUBREL with PUBCOMP.

This was found by reading the code, so the first step is a test that confirms the exception for each of the four packets.

Expected

  • No acknowledgement packet with an unknown packet id throws or closes unrelated state.
  • An unknown PUBREL is answered with PUBCOMP, carrying reason code 0x92 for MQTT 5 and plain PUBCOMP for MQTT 3.1.1.
  • The correct handling of an unknown PUBACK, PUBREC and PUBCOMP is taken from the specification text, not assumed: where the specification defines a response (for example a PUBREC for an unknown id), send it; otherwise ignore the packet. State the decision per packet in the pull request description with the section it comes from.

Test plan (test-first)

Spec scripts for v4 and v5, run through the runtime ITs of the MQTT server and of mqtt-kafka:

  • each of PUBACK, PUBREC, PUBCOMP and PUBREL with a packet id that was never used on the connection: the connection stays usable and the response above is sent;
  • PUBREL retransmitted after the PUBCOMP: answered again, no exception.

The first commit contains the failing scripts. Scripts are corrected only when they violate the protocol.

Notes

Found by a clause-by-clause audit of MQTT 3.1.1 and 5.0 conformance, by reading the code. Part of the MQTT conformance work under #512.

Activity

  1. self-assigned this
    on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions