Skip to content

Commit

Permalink
client: verify payload of SubscribeMultiple is not empty
Browse files Browse the repository at this point in the history
MQTT protocol 3.1.1 specifies that the payload in a SUBSCRIBE packet
must not be empty and must contain at least one topic filter and QoS
pair. Validate the input to SubscribeMultiple meets this requirement to
avoid protocol errors when communicating with a broker.

Fixes #384

Signed-off-by: Robert Weber <robertweber95@gmail.com>
  • Loading branch information
robbawebba committed Nov 16, 2019
1 parent 939f516 commit 6952317
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client.go
Expand Up @@ -754,6 +754,10 @@ func (c *client) SubscribeMultiple(filters map[string]byte, callback MessageHand
return token
}
}
if len(filters) == 0 {
token.setError(fmt.Errorf("topic filter/qos map must not be empty"))
return token
}
sub := packets.NewControlPacket(packets.Subscribe).(*packets.SubscribePacket)
if sub.Topics, sub.Qoss, err = validateSubscribeMap(filters); err != nil {
token.setError(err)
Expand Down

0 comments on commit 6952317

Please sign in to comment.