Skip to content

Commit

Permalink
bgpd:[GR] fix crash in print_bgp_vrfs json
Browse files Browse the repository at this point in the history
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 4af3b55

Ticket: #3861755

Testing:
Before the fix:

switch# show bgp vrfs json
Warning: connecting to bgpd...success!
{
.. <snippet>
}

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":{
.. <snippet>
}

switch# show bgp vrfs json
{
  "vrfs":{
.. <snippet>
}
switch# show bgp vrfs json
{
  "vrfs":{
.. <snippet>
}
switch# show bgp vrfs json
{
  "vrfs":{
.. <snippet>
}

Signed-off-by: Karthikeya Venkat Muppalla <[email protected]>
Signed-off-by: Pooja Jagadeesh Doijode <[email protected]>
  • Loading branch information
Karthikeya Venkat Muppalla authored and chiragshah6 committed Jan 10, 2025
1 parent ef0460b commit f390cda
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit f390cda

Please sign in to comment.