Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscribe_many with empty topic list emits malformed packet #387

Closed
KisImre opened this issue Apr 25, 2022 · 2 comments · Fixed by #392
Closed

subscribe_many with empty topic list emits malformed packet #387

KisImre opened this issue Apr 25, 2022 · 2 comments · Fixed by #392

Comments

@KisImre
Copy link

KisImre commented Apr 25, 2022

Description

Calling Client::subscribe_many with an empty topic list causes it to send a subscribe packet without any topic filter. According to [MQTT-3.8.3-3] "The payload of a SUBSCRIBE packet MUST contain at least one Topic Filter / QoS pair. A SUBSCRIBE packet with no payload is a protocol violation". v5 has the same requirement. When the broker gets this message is closes the connection due to a malformed packet.

  • This affects try_subscribe_many as well
  • Client::subscribe_many should return an error when called with an empty topic list
  • I haven't looked into rumqttd but it shouldn't accept these empty subscribe messages

Test setup

rumqttc v0.12.0
mosquitto version 2.0.14

Test code

use rumqttc::{Client, MqttOptions};

fn main() {
    let mqttoptions = MqttOptions::new("rumqtt-sync", "localhost", 1883);

    let (mut client, mut connection) = Client::new(mqttoptions, 10);

    client.subscribe_many(Vec::new()).unwrap();

    for notification in connection.iter() {
        println!("Notification = {:?}", notification);
    }
}

Output

Notification = Ok(Incoming(ConnAck(ConnAck { session_present: false, code: Success })))
Notification = Ok(Outgoing(Subscribe(1)))
Notification = Err(MqttState(Io(Custom { kind: ConnectionAborted, error: "connection closed by peer" })))

Broker log

mosquitto[2575]: 1650909678: New connection from ::1:39042 on port 1883.
mosquitto[2575]: 1650909678: New client connected from ::1:39042 as rumqtt-sync (p2, c1, k60).
mosquitto[2575]: 1650909678: Client rumqtt-sync disconnected due to malformed packet.

Packet

image

@de-sh
Copy link
Contributor

de-sh commented Apr 26, 2022

Thank you for pointing this out @KisImre. I have opened a branch to work on a possible solution to this. Do let me know your thoughts on the included changes.

@KisImre
Copy link
Author

KisImre commented Apr 27, 2022

Thank you for the fix, it looks good to me. Maybe it would be worth adding a check to Subscribe::read as well to prevent future issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants