From f390cdaf32c172c7fb5ed05ee341ea8acbc6e1bc Mon Sep 17 00:00:00 2001 From: Karthikeya Venkat Muppalla Date: Thu, 11 Apr 2024 16:58:22 -0700 Subject: [PATCH] bgpd:[GR] fix crash in print_bgp_vrfs json When BGP is in warm boot and `show bgp vrfs json` is executed more than once, bgpd crashes in print_bgp_vrfs. This is happening because of JSON object is being added multiple times to the JSON array with out allocating everytime in the for loop and when json is freed, it causes the crash. NOTE: This commit needs to be integrated with original commit 4af3b559 Ticket: #3861755 Testing: Before the fix: switch# show bgp vrfs json Warning: connecting to bgpd...success! { .. } switch# show bgp vrfs json Warning: closing connection to bgpd because of an I/O error! Warning: connecting to bgpd...failed! After the fix: BGP no longer crashes on `show bgp vrfs json` command and it works as expected. switch# show bgp vrfs json { "vrfs":{ .. } switch# show bgp vrfs json { "vrfs":{ .. } switch# show bgp vrfs json { "vrfs":{ .. } switch# show bgp vrfs json { "vrfs":{ .. } Signed-off-by: Karthikeya Venkat Muppalla Signed-off-by: Pooja Jagadeesh Doijode --- bgpd/bgp_vty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 18d3fdae7ff0..b13d5abe45c3 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -11227,11 +11227,11 @@ static void print_bgp_vrfs(struct bgp *bgp, struct vty *vty, json_object *json, safi_t safi = SAFI_UNICAST; struct graceful_restart_info *gr_info; json_object *json_gr = NULL; - json_gr = json_object_new_object(); json_object *json_grs = NULL; json_grs = json_object_new_array(); for (afi = AFI_IP; afi <= AFI_IP6; afi++) { + json_gr = json_object_new_object(); json_object_string_add( json_gr, "addressFamily", get_afi_safi_str(afi, safi, false));