From d1b91f2aef7eadeb4eefbc8c483274e1dffc2dde Mon Sep 17 00:00:00 2001 From: Igor Putovny Date: Wed, 28 May 2025 14:40:20 +0200 Subject: [PATCH] Send message when bgp_check_capabilities() fails --- proto/bgp/packets.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 95c34f025..e16001540 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -995,7 +995,21 @@ bgp_rx_open(struct bgp_conn *conn, byte *pkt, uint len) /* RFC 5492 5 - check for required capabilities */ if (p->cf->capabilities && !bgp_check_capabilities(conn, failed_caps)) - { bgp_error(conn, 2, 7, NULL, 0); return; } + { + byte buf[32] = { 0 }; + byte *end = bgp_write_capabilities(failed_caps, buf); + + /* Send empty message if conn->buf has insufficient size or when write buffer is empty */ + if (end > buf + sizeof(conn->buf) || end == buf) + bgp_error(conn, 2, 7, NULL, 0); + else + { + memcpy(conn->buf, buf, end - buf); + bgp_error(conn, 2, 7, conn->buf, end - buf); + } + + return; + } struct bgp_caps *caps = conn->remote_caps; -- 2.47.2