diff options
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bmp.go | 7 | ||||
-rw-r--r-- | packet/bmp_test.go | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/packet/bmp.go b/packet/bmp.go index eceb1272..bc789c66 100644 --- a/packet/bmp.go +++ b/packet/bmp.go @@ -541,7 +541,10 @@ const ( func ParseBMPMessage(data []byte) (*BMPMessage, error) { msg := &BMPMessage{} - msg.Header.DecodeFromBytes(data) + err := msg.Header.DecodeFromBytes(data) + if err != nil { + return nil, err + } data = data[BMP_HEADER_SIZE:msg.Header.Length] switch msg.Header.Type { @@ -564,7 +567,7 @@ func ParseBMPMessage(data []byte) (*BMPMessage, error) { data = data[BMP_PEER_HEADER_SIZE:] } - err := msg.Body.ParseBody(msg, data) + err = msg.Body.ParseBody(msg, data) if err != nil { return nil, err } diff --git a/packet/bmp_test.go b/packet/bmp_test.go index c1226088..e07c2455 100644 --- a/packet/bmp_test.go +++ b/packet/bmp_test.go @@ -16,6 +16,7 @@ package bgp import ( + "github.com/stretchr/testify/assert" "reflect" "testing" ) @@ -64,3 +65,9 @@ func Test_RouteMonitoring(t *testing.T) { p0 := NewBMPPeerHeader(0, false, 1000, "fe80::6e40:8ff:feab:2c2a", 70000, "10.0.0.2", 1) verify(t, NewBMPRouteMonitoring(*p0, m)) } + +func Test_BogusHeader(t *testing.T) { + h, err := ParseBMPMessage(make([]byte, 10)) + assert.Nil(t, h) + assert.NotNil(t, err) +} |