From 0c74220c6e841a3ca0c8534b34a138d5d05a1ebb Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 16 Jan 2024 14:37:16 +0200 Subject: [PATCH] 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 --- bgpd/bgp_open.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index 8b4f97d625..cb13801745 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -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);