summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2022-01-12 14:36:58 +0300
committerGitHub <noreply@github.com>2022-01-12 14:36:58 +0300
commit4d33086cadd1a1094eb29e7f261d0d3a2ac4ccfd (patch)
treeba2f6c4e5d9990fd210e30a63c0477ac92c3be3d
parent499841d123be7e41c9e90c080725d8edc490bc60 (diff)
parented284e2338111ff367087bc87f5ad9c67dd9e6cc (diff)
Merge pull request #10317 from ton31337/fix/shutdown_msg
bgpd: Make sure we are playing with non-NULL for bgp shutdown message
-rw-r--r--bgpd/bgpd.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 6d0fd2fdd6..56e299e4cc 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -4320,10 +4320,6 @@ void bgp_shutdown_enable(struct bgp *bgp, const char *msg)
struct listnode *node;
/* length(1) + message(N) */
uint8_t data[BGP_ADMIN_SHUTDOWN_MSG_LEN + 1];
- size_t datalen = strlen(msg);
-
- data[0] = datalen;
- memcpy(data + 1, msg, datalen);
/* do nothing if already shut down */
if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
@@ -4341,15 +4337,24 @@ void bgp_shutdown_enable(struct bgp *bgp, const char *msg)
/* send a RFC 4486 notification message if necessary */
if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
- if (msg)
+ if (msg) {
+ size_t datalen = strlen(msg);
+
+ if (datalen > BGP_ADMIN_SHUTDOWN_MSG_LEN)
+ datalen = BGP_ADMIN_SHUTDOWN_MSG_LEN;
+
+ data[0] = datalen;
+ memcpy(data + 1, msg, datalen);
+
bgp_notify_send_with_data(
peer, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, data,
datalen + 1);
- else
+ } else {
bgp_notify_send(
peer, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN);
+ }
}
/* reset start timer to initial value */