Merge pull request #5450 from donaldsharp/rpki_node_issues

bgpd: Prevent crash in bgp_table_range_lookup
This commit is contained in:
Sri Mohana Singamsetty 2019-12-02 17:15:35 -08:00 committed by GitHub
commit 96fda36733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -159,7 +159,8 @@ void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p,
if (node == NULL)
return;
while (node->p.prefixlen <= p->prefixlen && prefix_match(&node->p, p)) {
while (node &&
node->p.prefixlen <= p->prefixlen && prefix_match(&node->p, p)) {
if (bgp_node_has_bgp_path_info_data(node)
&& node->p.prefixlen == p->prefixlen) {
matched = node;
@ -169,14 +170,20 @@ void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p,
&p->u.prefix, node->p.prefixlen)]);
}
if (!node)
return;
if (matched == NULL && node->p.prefixlen <= maxlen
&& prefix_match(p, &node->p) && node->parent == NULL)
matched = node;
else if ((matched == NULL && node->p.prefixlen > maxlen) || !node->parent)
return;
else if (matched == NULL)
else if (matched == NULL && node->parent)
matched = node = bgp_node_from_rnode(node->parent);
if (!matched)
return;
if (bgp_node_has_bgp_path_info_data(matched)) {
bgp_lock_node(matched);
listnode_add(matches, matched);