From aa87dfb69e1b839f75132330b53cbc3600c491f7 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Wed, 29 Sep 2021 18:02:16 +0200 Subject: [PATCH] Comply with protocol spec to check for non-0 packet ID --- mqttpacket.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+), 0 deletions(-) diff --git a/mqttpacket.cpp b/mqttpacket.cpp index 6bb5e7e..f729db4 100644 --- a/mqttpacket.cpp +++ b/mqttpacket.cpp @@ -425,6 +425,11 @@ void MqttPacket::handleSubscribe() uint16_t packet_id = readTwoBytesToUInt16(); + if (packet_id == 0) + { + throw ProtocolError("Packet ID 0 when subscribing is invalid."); // [MQTT-2.3.1-1] + } + Authentication &authentication = *ThreadAuth::getAuth(); std::list subs_reponse_codes; @@ -478,6 +483,11 @@ void MqttPacket::handleUnsubscribe() uint16_t packet_id = readTwoBytesToUInt16(); + if (packet_id == 0) + { + throw ProtocolError("Packet ID 0 when unsubscribing is invalid."); // [MQTT-2.3.1-1] + } + while (remainingAfterPos() > 0) { uint16_t topicLength = readTwoBytesToUInt16(); @@ -534,6 +544,11 @@ void MqttPacket::handlePublish() packet_id_pos = pos; packet_id = readTwoBytesToUInt16(); + if (packet_id == 0) + { + throw ProtocolError("Packet ID 0 when publishing is invalid."); // [MQTT-2.3.1-1] + } + if (qos == 1) { PubAck pubAck(packet_id); -- libgit2 0.21.4