Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/packet/bgp: fix SoftVersion capability parser to check the input …
…length func (c *CapSoftwareVersion) DecodeFromBytes(data []byte) error { c.DefaultParameterCapability.DecodeFromBytes(data) data = data[2:] if len(data) < 2 { return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilitySoftwareVersion bytes allowed") } softwareVersionLen := uint8(data[0]) if len(data[1:]) < int(softwareVersionLen) || softwareVersionLen > 64 { return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "invalid length of software version capablity") } c.SoftwareVersionLen = softwareVersionLen c.SoftwareVersion = string(data[1:c.SoftwareVersionLen]) // ivg: note the crash is here return nil } Notice that `softwareVersionLen` is not checked for `0`, so `data[1:c.SoftwareVersionLen]` becomes `data[1:0]`, which leads to a runtime panic.
- Loading branch information