bgpd: Set hostname capability received flag only if parsed correctly

If we receive a malformed packet, we might end-up with a bad state.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2024-01-16 14:37:16 +02:00
parent 9b178d246e
commit 0c74220c6e

View File

@ -818,8 +818,6 @@ static int bgp_capability_hostname(struct peer *peer,
size_t end = stream_get_getp(s) + hdr->length;
uint8_t len;
SET_FLAG(peer->cap, PEER_CAP_HOSTNAME_RCV);
len = stream_getc(s);
if (stream_get_getp(s) + len > end) {
flog_warn(
@ -877,6 +875,8 @@ static int bgp_capability_hostname(struct peer *peer,
peer->domainname = XSTRDUP(MTYPE_BGP_PEER_HOST, str);
}
SET_FLAG(peer->cap, PEER_CAP_HOSTNAME_RCV);
if (bgp_debug_neighbor_events(peer)) {
zlog_debug("%s received hostname %s, domainname %s", peer->host,
peer->hostname, peer->domainname);