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);