summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
authorEiichiro Watanabe <a16tochjp@gmail.com>2017-02-03 17:39:13 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-02-04 06:28:25 -0800
commit7aff4a6c5841b2ec39ff4c96e8b654f78c7026d8 (patch)
treee9342201606be29ee0c195c7ad7dde0f80223c1a /packet
parent64360afd459436a49a1f1254cca21fffbe6945b5 (diff)
packet: Avoid panic() during decoding BMP messages
Diffstat (limited to 'packet')
-rw-r--r--packet/bmp/bmp.go12
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
}