From a542b8544e7ec330922ed18e93051cc21969776c Mon Sep 17 00:00:00 2001 From: Skyler Ross Date: Mon, 4 Mar 2024 13:13:11 -0800 Subject: [PATCH 1/2] fix(rumqttd/protocol/v5): Properly parse ConnAck and UnsubAck packets Signed-off-by: Skyler Ross --- rumqttd/src/protocol/v5/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rumqttd/src/protocol/v5/mod.rs b/rumqttd/src/protocol/v5/mod.rs index b8916ae55..149afb0fe 100644 --- a/rumqttd/src/protocol/v5/mod.rs +++ b/rumqttd/src/protocol/v5/mod.rs @@ -426,7 +426,14 @@ impl Protocol for V5 { let (pubcomp, properties) = pubcomp::read(fixed_header, packet)?; Packet::PubComp(pubcomp, properties) } - _ => unreachable!(), + PacketType::ConnAck => { + let (puback, properties) = connack::read(fixed_header, packet)?; + Packet::ConnAck(puback, properties) + } + PacketType::UnsubAck => { + let (unsuback, properties) = unsuback::read(fixed_header, packet)?; + Packet::UnsubAck(unsuback, properties) + } }; Ok(packet) From 9b8bbb1387c64045cf9016406a4fccbcf114197f Mon Sep 17 00:00:00 2001 From: Skyler Ross Date: Fri, 8 Mar 2024 12:09:05 -0800 Subject: [PATCH 2/2] chore: address PR comments Signed-off-by: Skyler Ross --- rumqttd/CHANGELOG.md | 1 + rumqttd/src/protocol/v4/mod.rs | 1 - rumqttd/src/protocol/v5/mod.rs | 16 ++++++++-------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rumqttd/CHANGELOG.md b/rumqttd/CHANGELOG.md index e05da5cea..a84cce346 100644 --- a/rumqttd/CHANGELOG.md +++ b/rumqttd/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - MQTT keep alive interval - record client id for remote link's span - session present flag in connack +- (MQTT v5) handle connack and unsuback packets properly instead of panic. ### Security diff --git a/rumqttd/src/protocol/v4/mod.rs b/rumqttd/src/protocol/v4/mod.rs index aa454663d..41ff44da3 100644 --- a/rumqttd/src/protocol/v4/mod.rs +++ b/rumqttd/src/protocol/v4/mod.rs @@ -334,7 +334,6 @@ impl Protocol for V4 { // v4 Disconnect packet gets handled in the previous check, this branch gets hit when // Disconnect packet has properties which is only valid for v5 PacketType::Disconnect => return Err(Error::InvalidProtocol), - _ => unreachable!(), }; Ok(packet) diff --git a/rumqttd/src/protocol/v5/mod.rs b/rumqttd/src/protocol/v5/mod.rs index 149afb0fe..fa2bd6c27 100644 --- a/rumqttd/src/protocol/v5/mod.rs +++ b/rumqttd/src/protocol/v5/mod.rs @@ -388,6 +388,10 @@ impl Protocol for V5 { connect::read(fixed_header, packet)?; Packet::Connect(connect, properties, will, willproperties, login) } + PacketType::ConnAck => { + let (puback, properties) = connack::read(fixed_header, packet)?; + Packet::ConnAck(puback, properties) + } PacketType::Publish => { let (publish, properties) = publish::read(fixed_header, packet)?; Packet::Publish(publish, properties) @@ -408,6 +412,10 @@ impl Protocol for V5 { let (unsubscribe, properties) = unsubscribe::read(fixed_header, packet)?; Packet::Unsubscribe(unsubscribe, properties) } + PacketType::UnsubAck => { + let (unsuback, properties) = unsuback::read(fixed_header, packet)?; + Packet::UnsubAck(unsuback, properties) + } PacketType::PingReq => Packet::PingReq(PingReq), PacketType::PingResp => Packet::PingResp(PingResp), PacketType::Disconnect => { @@ -426,14 +434,6 @@ impl Protocol for V5 { let (pubcomp, properties) = pubcomp::read(fixed_header, packet)?; Packet::PubComp(pubcomp, properties) } - PacketType::ConnAck => { - let (puback, properties) = connack::read(fixed_header, packet)?; - Packet::ConnAck(puback, properties) - } - PacketType::UnsubAck => { - let (unsuback, properties) = unsuback::read(fixed_header, packet)?; - Packet::UnsubAck(unsuback, properties) - } }; Ok(packet)