From: Donatas Abraitis Date: Wed, 9 Feb 2022 14:41:14 +0000 (+0200) Subject: bgpd: Check for NULL inside aspath_unintern() X-Git-Tag: pim6-testing-20220430~325^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=b7b3e63cc0ef69b30d73fd2bf1593aad665c26f5;p=matthieu%2Ffrr.git bgpd: Check for NULL inside aspath_unintern() It's not always guarded, just check inside. Signed-off-by: Donatas Abraitis --- diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index 192cd6ca82..dd27c9f6a1 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -328,7 +328,12 @@ void aspath_free(struct aspath *aspath) void aspath_unintern(struct aspath **aspath) { struct aspath *ret; - struct aspath *asp = *aspath; + struct aspath *asp; + + if (!*aspath) + return; + + asp = *aspath; if (asp->refcnt) asp->refcnt--; diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 3c3fd174f6..607e5152b5 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1093,8 +1093,7 @@ void bgp_attr_unintern_sub(struct attr *attr) struct cluster_list *cluster; /* aspath refcount shoud be decrement. */ - if (attr->aspath) - aspath_unintern(&attr->aspath); + aspath_unintern(&attr->aspath); UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)); if (attr->community) @@ -3534,14 +3533,12 @@ done: * we can chuck as4_aggregator and as4_path alltogether in order * to save memory */ - if (as4_path) { - /* - * unintern - it is in the hash - * The flag that we got this is still there, but that - * does not do any trouble - */ - aspath_unintern(&as4_path); - } + /* + * unintern - it is in the hash + * The flag that we got this is still there, but that + * does not do any trouble + */ + aspath_unintern(&as4_path); transit = bgp_attr_get_transit(attr); if (ret != BGP_ATTR_PARSE_ERROR) { diff --git a/tests/bgpd/test_aspath.c b/tests/bgpd/test_aspath.c index c2d39752ab..7288dc0869 100644 --- a/tests/bgpd/test_aspath.c +++ b/tests/bgpd/test_aspath.c @@ -1062,8 +1062,7 @@ static void parse_test(struct test_segment *t) printf("\n"); - if (asp) - aspath_unintern(&asp); + aspath_unintern(&asp); } /* prepend testing */ @@ -1117,8 +1116,7 @@ static void empty_prepend_test(struct test_segment *t) printf(FAILED "!\n"); printf("\n"); - if (asp1) - aspath_unintern(&asp1); + aspath_unintern(&asp1); aspath_free(asp2); } @@ -1277,10 +1275,8 @@ static int handle_attr_test(struct aspath_tests *t) } out: - if (attr.aspath) - aspath_unintern(&attr.aspath); - if (asp) - aspath_unintern(&asp); + aspath_unintern(&attr.aspath); + aspath_unintern(&asp); return failed - initfail; }