diff options
author | Eiichiro Watanabe <a16tochjp@gmail.com> | 2017-02-03 17:39:13 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-02-04 06:28:25 -0800 |
commit | 7aff4a6c5841b2ec39ff4c96e8b654f78c7026d8 (patch) | |
tree | e9342201606be29ee0c195c7ad7dde0f80223c1a /packet | |
parent | 64360afd459436a49a1f1254cca21fffbe6945b5 (diff) |
packet: Avoid panic() during decoding BMP messages
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bmp/bmp.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/packet/bmp/bmp.go b/packet/bmp/bmp.go index 084a0d16..19e2840e 100644 --- a/packet/bmp/bmp.go +++ b/packet/bmp/bmp.go @@ -540,9 +540,15 @@ const ( BMP_MSG_TERMINATION ) -func ParseBMPMessage(data []byte) (*BMPMessage, error) { - msg := &BMPMessage{} - err := msg.Header.DecodeFromBytes(data) +func ParseBMPMessage(data []byte) (msg *BMPMessage, err error) { + defer func() { + if r := recover(); r != nil { + err = fmt.Errorf("not all data bytes are available") + } + }() + + msg = &BMPMessage{} + err = msg.Header.DecodeFromBytes(data) if err != nil { return nil, err } |