Skip to content

Commit

Permalink
Fix UnsubAck length check (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Jan 26, 2020
1 parent 0eea2ef commit be12606
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func TestPacketParseError(t *testing.T) {
"UnsubAck_InvalidFlag": {
0x01, []byte{}, &pktUnsubAck{}, ErrInvalidPacket,
},
"UnsubAck_ShortLength": {
0x00, []byte{}, &pktUnsubAck{}, ErrInvalidPacketLength,
},
}

for name, c := range cases {
Expand Down
5 changes: 4 additions & 1 deletion unsuback.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ type pktUnsubAck struct {

func (p *pktUnsubAck) Parse(flag byte, contents []byte) (*pktUnsubAck, error) {
if flag != 0 {
return nil, wrapError(ErrInvalidPacket, "parsing SUBACK")
return nil, wrapError(ErrInvalidPacket, "parsing UNSUBACK")
}
if len(contents) < 2 {
return nil, wrapError(ErrInvalidPacketLength, "parsing UNSUBACK")
}
p.ID = uint16(contents[0])<<8 | uint16(contents[1])
return p, nil
Expand Down

0 comments on commit be12606

Please sign in to comment.