Merge pull request #10546 from ton31337/fix/check_for_null_inside_unintern

bgpd: Check for NULL inside aspath_unintern()
This commit is contained in:
Russ White 2022-02-15 12:59:45 -05:00 committed by GitHub
commit 8f689a6e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 19 deletions

View File

@ -328,7 +328,12 @@ void aspath_free(struct aspath *aspath)
void aspath_unintern(struct aspath **aspath) void aspath_unintern(struct aspath **aspath)
{ {
struct aspath *ret; struct aspath *ret;
struct aspath *asp = *aspath; struct aspath *asp;
if (!*aspath)
return;
asp = *aspath;
if (asp->refcnt) if (asp->refcnt)
asp->refcnt--; asp->refcnt--;

View File

@ -1086,8 +1086,7 @@ void bgp_attr_unintern_sub(struct attr *attr)
struct lcommunity *lcomm = NULL; struct lcommunity *lcomm = NULL;
/* aspath refcount shoud be decrement. */ /* 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)); UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH));
if (attr->community) if (attr->community)
@ -3494,14 +3493,12 @@ done:
* we can chuck as4_aggregator and as4_path alltogether in order * we can chuck as4_aggregator and as4_path alltogether in order
* to save memory * to save memory
*/ */
if (as4_path) { /*
/* * unintern - it is in the hash
* unintern - it is in the hash * The flag that we got this is still there, but that
* The flag that we got this is still there, but that * does not do any trouble
* does not do any trouble */
*/ aspath_unintern(&as4_path);
aspath_unintern(&as4_path);
}
transit = bgp_attr_get_transit(attr); transit = bgp_attr_get_transit(attr);
if (ret != BGP_ATTR_PARSE_ERROR) { if (ret != BGP_ATTR_PARSE_ERROR) {

View File

@ -1062,8 +1062,7 @@ static void parse_test(struct test_segment *t)
printf("\n"); printf("\n");
if (asp) aspath_unintern(&asp);
aspath_unintern(&asp);
} }
/* prepend testing */ /* prepend testing */
@ -1117,8 +1116,7 @@ static void empty_prepend_test(struct test_segment *t)
printf(FAILED "!\n"); printf(FAILED "!\n");
printf("\n"); printf("\n");
if (asp1) aspath_unintern(&asp1);
aspath_unintern(&asp1);
aspath_free(asp2); aspath_free(asp2);
} }
@ -1277,10 +1275,8 @@ static int handle_attr_test(struct aspath_tests *t)
} }
out: out:
if (attr.aspath) aspath_unintern(&attr.aspath);
aspath_unintern(&attr.aspath); aspath_unintern(&asp);
if (asp)
aspath_unintern(&asp);
return failed - initfail; return failed - initfail;
} }