diff options
author | Tim Evens <tievens@cisco.com> | 2016-08-02 07:21:54 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-08-02 07:21:54 +0900 |
commit | e847113b526d9389bd939669819c8d56854a93fb (patch) | |
tree | bd908e26eebf81a216b997e90d844f6c3fa50a3b /packet | |
parent | 0d53551b0a5f297a3fbf47cf7a79ae7c2993bd7e (diff) |
packet: Change graceful restart tuple (afi/safi/flags) parsing to use capability length instead of remaining parameter length.
Fixes #1037
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp/bgp.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index f309f8dd..b74aa838 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -362,12 +362,18 @@ func (c *CapGracefulRestart) DecodeFromBytes(data []byte) error { c.Flags = uint8(restart >> 12) c.Time = restart & 0xfff data = data[2:] - c.Tuples = make([]*CapGracefulRestartTuple, 0, len(data)/4) - for len(data) >= 4 { - t := &CapGracefulRestartTuple{binary.BigEndian.Uint16(data[0:2]), - data[2], data[3]} - c.Tuples = append(c.Tuples, t) - data = data[4:] + + valueLen := int(c.CapLen) - 2 + + if valueLen >= 4 && len(data) >= valueLen { + c.Tuples = make([]*CapGracefulRestartTuple, 0, valueLen/4) + + for i := valueLen; i >= 4; i -= 4 { + t := &CapGracefulRestartTuple{binary.BigEndian.Uint16(data[0:2]), + data[2], data[3]} + c.Tuples = append(c.Tuples, t) + data = data[4:] + } } return nil } |