Merge pull request #16579 from opensourcerouting/fix/bgpd_use_after_free_no_router_bgp

bgpd: Avoid use-after-free when doing `no router bgp` with auto created instances
This commit is contained in:
Donald Sharp 2024-08-14 08:39:25 -04:00 committed by GitHub
commit 9356e3fdb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1695,15 +1695,18 @@ DEFUN (no_router_bgp,
/* Cannot delete default instance if vrf instances exist */
if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
struct listnode *node;
struct listnode *node, *nnode;
struct bgp *tmp_bgp;
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, tmp_bgp)) {
if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
continue;
if (CHECK_FLAG(tmp_bgp->vrf_flags, BGP_VRF_AUTO))
if (CHECK_FLAG(tmp_bgp->vrf_flags,
BGP_VRF_AUTO)) {
bgp_delete(tmp_bgp);
continue;
}
if (CHECK_FLAG(
tmp_bgp->af_flags[AFI_IP]