Skip to content

Commit 477ac71

Browse files
authored
Merge pull request #19424 from FRRouting/mergify/bp/stable/10.4/pr-19362
bgpd: Fix crash due to dangling pointer in bnc nht_info (backport #19362)
2 parents 9d52ffe + 04fe58c commit 477ac71

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

bgpd/bgp_nht.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -532,26 +532,23 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer)
532532
if (!peer)
533533
return;
534534

535-
/*
536-
* In case the below check evaluates true and if
537-
* the bnc has not been freed at this point, then
538-
* we might have to do something similar to what's
539-
* done in bgp_unlink_nexthop_by_peer(). Since
540-
* bgp_unlink_nexthop_by_peer() loops through the
541-
* nodes of V6 nexthop cache to find the bnc, it is
542-
* currently not being called here.
543-
*/
544-
if (!sockunion2hostprefix(&peer->connection->su, &p))
545-
return;
546-
/*
547-
* Gather the ifindex for if up/down events to be
548-
* tagged into this fun
549-
*/
550-
if (afi == AFI_IP6 &&
551-
IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr))
552-
ifindex = peer->connection->su.sin6.sin6_scope_id;
553-
bnc = bnc_find(&peer->bgp->nexthop_cache_table[family2afi(p.family)],
554-
&p, 0, ifindex);
535+
if (!sockunion2hostprefix(&peer->connection->su, &p)) {
536+
/*
537+
* If peer->connection->su is cleared before peer deletion,
538+
* find the bnc whose nht_info matches the peer and free it.
539+
*/
540+
bnc = bgp_find_ipv6_nexthop_matching_peer(peer);
541+
} else {
542+
/*
543+
* Gather the ifindex for if up/down events to be
544+
* tagged into this fun
545+
*/
546+
if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr))
547+
ifindex = peer->connection->su.sin6.sin6_scope_id;
548+
bnc = bnc_find(&peer->bgp->nexthop_cache_table[family2afi(p.family)], &p, 0,
549+
ifindex);
550+
}
551+
555552
if (!bnc) {
556553
if (BGP_DEBUG(nht, NHT))
557554
zlog_debug(

0 commit comments

Comments
 (0)