From ea813698ae78bc0460e2fe978124c654b44125a1 Mon Sep 17 00:00:00 2001 From: bemasher Date: Wed, 29 Oct 2014 14:28:00 -0600 Subject: [PATCH] Add new error case for SCM parsing. Will error if packet is too short. Adds slice upper bound for checksum. --- scm/scm.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scm/scm.go b/scm/scm.go index 2ea5a39be..298739c3d 100644 --- a/scm/scm.go +++ b/scm/scm.go @@ -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 }