Skip to content

Commit

Permalink
Add new error case for SCM parsing.
Browse files Browse the repository at this point in the history
Will error if packet is too short.
Adds slice upper bound for checksum.
  • Loading branch information
bemasher committed Oct 29, 2014
1 parent 2b055fc commit ea81369
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scm/scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ func NewParser() (p Parser) {
func (p Parser) Parse(data parse.Data) (msg parse.Message, err error) {
var scm SCM

if p.Checksum(data.Bytes[2:]) != 0 {
if l := len(data.Bytes); l < 12 {
err = fmt.Errorf("packet too short: %d", l)
return
}
if p.Checksum(data.Bytes[2:12]) != 0 {
err = errors.New("checksum failed")
return
}
Expand Down

0 comments on commit ea81369

Please sign in to comment.