From 45d9af1857e5655f54c47d163e6f0a1c50c7e305 Mon Sep 17 00:00:00 2001 From: Dmytro Shytyi Date: Fri, 19 May 2023 11:40:21 +0200 Subject: [PATCH] bgpd: fix the bgp->name null pointer Avoid the crash provoked by bgp->name null pointer in snmp context. If bgp->name == NULL, replace it by "defalut" vrf name. Signed-off-by: Dmytro Shytyi --- bgpd/bgp_mplsvpn_snmp.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bgpd/bgp_mplsvpn_snmp.c b/bgpd/bgp_mplsvpn_snmp.c index 0208a6f5a549..e24dd676c1cb 100644 --- a/bgpd/bgp_mplsvpn_snmp.c +++ b/bgpd/bgp_mplsvpn_snmp.c @@ -581,6 +581,7 @@ static int bgp_vrf_check_update_active(struct bgp *bgp, struct interface *ifp) bool new_active = false; oid trap; struct index_oid trap_index[2]; + const char *vrf_name; if (!is_bgp_vrf_mplsvpn(bgp) || bgp->snmp_stats == NULL || !bgp_mplsvpn_notif_enable) @@ -596,14 +597,18 @@ static int bgp_vrf_check_update_active(struct bgp *bgp, struct interface *ifp) else trap = MPLSL3VPNDOWN; + if (bgp->name) + vrf_name = bgp->name; + else + vrf_name = VRF_DEFAULT_NAME; /* * first index vrf_name + ifindex * second index vrf_name */ - trap_index[1].indexlen = strnlen(bgp->name, VRF_NAMSIZ); - oid_copy_str(trap_index[0].indexname, bgp->name, + trap_index[1].indexlen = strnlen(vrf_name, VRF_NAMSIZ); + oid_copy_str(trap_index[0].indexname, vrf_name, trap_index[1].indexlen); - oid_copy_str(trap_index[1].indexname, bgp->name, + oid_copy_str(trap_index[1].indexname, vrf_name, trap_index[1].indexlen); trap_index[0].indexlen = trap_index[1].indexlen + sizeof(ifindex_t);