Skip to content

Commit

Permalink
bgpd: Fix core during received-routes brief json cmd
Browse files Browse the repository at this point in the history
When a route-map causes a prefix to be denied (with soft-reconfig
enabled), executing show bgp nbr xyz received-routes brief json results
in invoking peer_adj_routes_brief() where prefix_path_count can be 0 and a
premature free of json happens.

This free of json was originally intended for a no-op condition i.e.
to free up the json objects which are originally allocated and not used.

Fixing this.

Ticket :#4081784

Signed-off-by: Rajasekar Raja <[email protected]>
  • Loading branch information
raja-rajasekar authored and donaldsharp committed Dec 18, 2024
1 parent 4c633d2 commit 0d67141
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -14527,6 +14527,7 @@ static int peer_adj_routes_brief(struct vty *vty, struct peer *peer, afi_t afi,
struct bgp_adj_in *ain = NULL;
struct bgp_adj_out *adj = NULL;
struct peer_af *paf = NULL;
bool json_pfx_populated = false;

if (type == bgp_show_adj_route_received) {
for (ain = dest->adj_in; ain; ain = ain->next) {
Expand All @@ -14545,6 +14546,7 @@ static int peer_adj_routes_brief(struct vty *vty, struct peer *peer, afi_t afi,
bgp_prefix_json_info_add(vty, json_flags, json_info,
prefix_path_count, multi_path_count);
json_object_object_addf(json_prefix, json_info, "%pFX", rn_p);
json_pfx_populated = true;
}
ain = NULL;
} else if (type == bgp_show_adj_route_advertised) {
Expand All @@ -14569,12 +14571,14 @@ static int peer_adj_routes_brief(struct vty *vty, struct peer *peer, afi_t afi,
multi_path_count);
json_object_object_addf(json_prefix, json_info, "%pFX",
rn_p);
json_pfx_populated = true;
}
}
adj = NULL;
}

if (prefix_path_count == 0) {
/* Free up the below only if json_pfx is not populated */
if (prefix_path_count == 0 && !json_pfx_populated) {
json_object_free(json_info);
json_object_free(json_flags);
}
Expand Down

0 comments on commit 0d67141

Please sign in to comment.