diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index 3f6d13fbfa26..0fe859f936fe 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -1151,7 +1151,7 @@ bool aspath_firstas_check(struct aspath *aspath, as_t asno) unsigned int aspath_get_first_as(struct aspath *aspath) { - if (aspath == NULL || aspath->segments == NULL) + if (aspath == NULL || aspath->segments == NULL || aspath->segments->length == 0) return 0; return aspath->segments->as[0]; diff --git a/tests/topotests/bgp_remove_private_as/test_bgp_remove_private_as.py b/tests/topotests/bgp_remove_private_as/test_bgp_remove_private_as.py index 8b965a161454..9fbf8898770f 100644 --- a/tests/topotests/bgp_remove_private_as/test_bgp_remove_private_as.py +++ b/tests/topotests/bgp_remove_private_as/test_bgp_remove_private_as.py @@ -41,6 +41,7 @@ from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from functools import partial +from lib.topolog import logger pytestmark = [pytest.mark.bgpd] @@ -389,6 +390,44 @@ def _validate_paths(remove_type): real_path = adj_rib_in["receivedRoutes"][pfx]["path"] return real_path == good_path + def __no_crash(): + output = json.loads( + tgen.gears["r2"].vtysh_cmd( + "show ip bgp neighbor 203.0.113.0 advertised-routes detail json" + ) + ) + logger.info(output) + logger.info(output["totalPrefixCounter"]) + if output["totalPrefixCounter"] != 0: + return True + return False + + def _crash_scenario(): + """add list of command making""" + tgen = get_topogen() + tgen.gears["r2"].vtysh_cmd( + """ + configure terminal + route-map OLDCORE-INTERNET-IN-IPv4 permit 5 + set as-path replace any 65398 + exit + route-map OLDCORE-INTERNET-OUT-IPv4 permit 5 + set as-path replace any 65399 + exit + router bgp 65002 + bgp deterministic-med + address-family ipv4 unicast + neighbor 203.0.113.0 remove-private-AS all + neighbor 203.0.113.0 soft-reconfiguration inbound + neighbor 203.0.113.0 route-map OLDCORE-INTERNET-IN-IPv4 in + neighbor 203.0.113.0 route-map OLDCORE-INTERNET-OUT-IPv4 out + exit-address-family + """ + ) + test_func = partial(__no_crash) + _, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5) + assert result == True, "bgpd may has major failure" + ####################### # Begin Test ####################### @@ -408,6 +447,13 @@ def _validate_paths(remove_type): # the old flag after each iteration so we only test the flags we expect. _change_remove_type(rmv_type, "del") + # verify that nulled as_path don't make a crash. + _change_remove_type("remove-private-AS all", "add") + _crash_scenario() + + +exit + if __name__ == "__main__": args = ["-s"] + sys.argv[1:]