Skip to content

Commit

Permalink
packet: fix FQDN capability parser
Browse files Browse the repository at this point in the history
Fixes #2708
  • Loading branch information
fujita committed Oct 31, 2023
1 parent 286c887 commit e26631c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,26 @@ func (c *CapFQDN) DecodeFromBytes(data []byte) error {
if len(data) < 2 {
return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilityFQDN bytes allowed")
}
rest := len(data)
if rest < 1 {
return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilityFQDN bytes allowed")
}
hostNameLen := uint8(data[0])
rest -= 1
c.HostNameLen = hostNameLen
if rest < int(hostNameLen) {
return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilityFQDN bytes allowed")
}
c.HostName = string(data[1 : c.HostNameLen+1])
rest -= int(hostNameLen)
if rest < 1 {
return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilityFQDN bytes allowed")
}
rest -= 1
domainNameLen := uint8(data[c.HostNameLen+1])
if rest < int(domainNameLen) {
return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilityFQDN bytes allowed")
}
c.DomainNameLen = domainNameLen
c.DomainName = string(data[c.HostNameLen+2:])
return nil
Expand Down

0 comments on commit e26631c

Please sign in to comment.