Expected behavior
This input appears to be a malformed PINGREQ, not a valid PINGREQ followed
by a PINGRESP:
C0 02 is PINGREQ with Remaining Length 2. PINGREQ has no variable
header or payload, so its Remaining Length must be 0 in both MQTT 3.1.1 and
MQTT 5.0:
The trailing D0 00 bytes are still inside the malformed PINGREQ frame.
Remaining Length defines the boundary of the current MQTT packet, so those bytes
should not start another packet.
Expected result: one failed MqttMessage for the malformed PINGREQ.
Actual behavior
MqttDecoder can decode the same input as a valid PINGREQ, then a valid
PINGRESP.
The decoder reaches the default branch in decodePayload for messages with no
payload, and returns null without checking that bytesRemainingInVariablePart
is zero. The same path is used by other MQTT message types with no payload, so
this is not specific to PINGREQ.
Netty version
4.1.x, 4.2.x, and 5.0.x.
Expected behavior
This input appears to be a malformed PINGREQ, not a valid PINGREQ followed
by a PINGRESP:
C0 02is PINGREQ with Remaining Length 2. PINGREQ has no variableheader or payload, so its Remaining Length must be 0 in both MQTT 3.1.1 and
MQTT 5.0:
The trailing
D0 00bytes are still inside the malformed PINGREQ frame.Remaining Length defines the boundary of the current MQTT packet, so those bytes
should not start another packet.
Expected result: one failed MqttMessage for the malformed PINGREQ.
Actual behavior
MqttDecoder can decode the same input as a valid PINGREQ, then a valid
PINGRESP.
The decoder reaches the default branch in
decodePayloadfor messages with nopayload, and returns
nullwithout checking thatbytesRemainingInVariablePartis zero. The same path is used by other MQTT message types with no payload, so
this is not specific to PINGREQ.
Netty version
4.1.x, 4.2.x, and 5.0.x.