mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-16 00:25:01 +00:00
Merge pull request #14506 from louis-6wind/fix-bgp-link-state
bgpd: fix link state coverity scan issues
This commit is contained in:
commit
b9cbecbd16
@ -780,7 +780,7 @@ static bool link_state_hash_cmp(const void *p1, const void *p2)
|
|||||||
|
|
||||||
if (!link_state1 && link_state2)
|
if (!link_state1 && link_state2)
|
||||||
return false;
|
return false;
|
||||||
if (!link_state1 && link_state2)
|
if (link_state1 && !link_state2)
|
||||||
return false;
|
return false;
|
||||||
if (!link_state1 && !link_state2)
|
if (!link_state1 && !link_state2)
|
||||||
return true;
|
return true;
|
||||||
@ -4982,7 +4982,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* BGP Link-State */
|
/* BGP Link-State */
|
||||||
if (attr && attr->link_state) {
|
if (attr->link_state) {
|
||||||
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
|
||||||
stream_putc(s, BGP_ATTR_LINK_STATE);
|
stream_putc(s, BGP_ATTR_LINK_STATE);
|
||||||
stream_putc(s, attr->link_state->length);
|
stream_putc(s, attr->link_state->length);
|
||||||
|
@ -31,7 +31,7 @@ struct bgp_linkstate_tlv_info {
|
|||||||
#define UNDEF_MULTPL 1
|
#define UNDEF_MULTPL 1
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
struct bgp_linkstate_tlv_info bgp_linkstate_tlv_infos[BGP_LS_TLV_MAX] = {
|
struct bgp_linkstate_tlv_info bgp_linkstate_tlv_infos[BGP_LS_TLV_MAX + 1] = {
|
||||||
/* NLRI TLV */
|
/* NLRI TLV */
|
||||||
[BGP_LS_TLV_LOCAL_NODE_DESCRIPTORS] = {"Local Node Descriptors", 1, MAX_SZ, UNDEF_MULTPL},
|
[BGP_LS_TLV_LOCAL_NODE_DESCRIPTORS] = {"Local Node Descriptors", 1, MAX_SZ, UNDEF_MULTPL},
|
||||||
[BGP_LS_TLV_REMOTE_NODE_DESCRIPTORS] = {"Remote Node Descriptors", 1, MAX_SZ, UNDEF_MULTPL},
|
[BGP_LS_TLV_REMOTE_NODE_DESCRIPTORS] = {"Remote Node Descriptors", 1, MAX_SZ, UNDEF_MULTPL},
|
||||||
@ -577,7 +577,8 @@ static bool bgp_linkstate_nlri_value_display(char *buf, size_t size,
|
|||||||
break;
|
break;
|
||||||
case BGP_LS_TLV_IP_REACHABILITY_INFORMATION:
|
case BGP_LS_TLV_IP_REACHABILITY_INFORMATION:
|
||||||
mask_length = pnt_decode8(&pnt);
|
mask_length = pnt_decode8(&pnt);
|
||||||
if (nlri_type == BGP_LINKSTATE_PREFIX4) {
|
if (nlri_type == BGP_LINKSTATE_PREFIX4 &&
|
||||||
|
((length - sizeof(mask_length)) <= sizeof(ipv4.s_addr))) {
|
||||||
memcpy(&ipv4.s_addr, pnt, length - sizeof(mask_length));
|
memcpy(&ipv4.s_addr, pnt, length - sizeof(mask_length));
|
||||||
if (json)
|
if (json)
|
||||||
json_object_string_addf(json, "ipReachability",
|
json_object_string_addf(json, "ipReachability",
|
||||||
@ -587,7 +588,8 @@ static bool bgp_linkstate_nlri_value_display(char *buf, size_t size,
|
|||||||
snprintfrr(buf, size, "%sIPv4:%pI4/%u",
|
snprintfrr(buf, size, "%sIPv4:%pI4/%u",
|
||||||
first ? "" : " ", &ipv4,
|
first ? "" : " ", &ipv4,
|
||||||
mask_length);
|
mask_length);
|
||||||
} else if (nlri_type == BGP_LINKSTATE_PREFIX6) {
|
} else if (nlri_type == BGP_LINKSTATE_PREFIX6 &&
|
||||||
|
((length - sizeof(mask_length)) <= sizeof(ipv6))) {
|
||||||
memcpy(&ipv6, pnt, length - sizeof(mask_length));
|
memcpy(&ipv6, pnt, length - sizeof(mask_length));
|
||||||
if (json)
|
if (json)
|
||||||
json_object_string_addf(json, "ipReachability",
|
json_object_string_addf(json, "ipReachability",
|
||||||
@ -1352,7 +1354,6 @@ static void bgp_linkstate_tlv_opaque_display(struct vty *vty, uint8_t *pnt,
|
|||||||
uint8_t *lim = pnt + length;
|
uint8_t *lim = pnt + length;
|
||||||
bool ospf_tlv_header;
|
bool ospf_tlv_header;
|
||||||
char tlv_type[6];
|
char tlv_type[6];
|
||||||
int i;
|
|
||||||
|
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
@ -1398,21 +1399,15 @@ static void bgp_linkstate_tlv_opaque_display(struct vty *vty, uint8_t *pnt,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
vty_out(vty, "\n%*sTLV type %u: 0x", indent, "", sub_type);
|
vty_out(vty, "\n%*sTLV type %u: ", indent, "", sub_type);
|
||||||
|
|
||||||
if (pnt + sub_length > lim) {
|
if (pnt + sub_length > lim) {
|
||||||
vty_out(vty, "Bad length received: %u\n", sub_length);
|
vty_out(vty, "Bad length received: %u\n", sub_length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < sub_length; i++) {
|
bgp_linkstate_tlv_hexa_display(vty, pnt, sub_length, NULL);
|
||||||
if (i != 0 && i % 8 == 0)
|
|
||||||
vty_out(vty, " ");
|
|
||||||
vty_out(vty, "%02x", *pnt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!json)
|
|
||||||
vty_out(vty, "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bgp_linkstate_tlv_rtm_capability_display(struct vty *vty,
|
static void bgp_linkstate_tlv_rtm_capability_display(struct vty *vty,
|
||||||
@ -1526,6 +1521,11 @@ static void bgp_linkstate_tlv_isis_area_indentifier_display(struct vty *vty,
|
|||||||
{
|
{
|
||||||
struct iso_address addr;
|
struct iso_address addr;
|
||||||
|
|
||||||
|
if (length > sizeof(addr.area_addr)) {
|
||||||
|
bgp_linkstate_tlv_hexa_display(vty, pnt, length, json);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
addr.addr_len = length;
|
addr.addr_len = length;
|
||||||
memcpy(addr.area_addr, pnt, length);
|
memcpy(addr.area_addr, pnt, length);
|
||||||
|
|
||||||
@ -1706,7 +1706,7 @@ void bgp_linkstate_tlv_attribute_display(struct vty *vty,
|
|||||||
json_tlv = json_object_new_object();
|
json_tlv = json_object_new_object();
|
||||||
json_object_object_add(json, tlv_type, json_tlv);
|
json_object_object_add(json, tlv_type, json_tlv);
|
||||||
|
|
||||||
if (type < BGP_LS_TLV_MAX &&
|
if (type <= BGP_LS_TLV_MAX &&
|
||||||
bgp_linkstate_tlv_infos[type].descr != NULL)
|
bgp_linkstate_tlv_infos[type].descr != NULL)
|
||||||
json_object_string_add(
|
json_object_string_add(
|
||||||
json_tlv, "description",
|
json_tlv, "description",
|
||||||
@ -1721,7 +1721,7 @@ void bgp_linkstate_tlv_attribute_display(struct vty *vty,
|
|||||||
"too high length received: %u", length);
|
"too high length received: %u", length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (type < BGP_LS_TLV_MAX &&
|
if (type <= BGP_LS_TLV_MAX &&
|
||||||
bgp_linkstate_tlv_infos[type].descr != NULL &&
|
bgp_linkstate_tlv_infos[type].descr != NULL &&
|
||||||
!bgp_ls_tlv_check_size(type, length))
|
!bgp_ls_tlv_check_size(type, length))
|
||||||
json_object_string_addf(
|
json_object_string_addf(
|
||||||
@ -1729,7 +1729,7 @@ void bgp_linkstate_tlv_attribute_display(struct vty *vty,
|
|||||||
"unexpected length received: %u",
|
"unexpected length received: %u",
|
||||||
length);
|
length);
|
||||||
} else {
|
} else {
|
||||||
if (type < BGP_LS_TLV_MAX &&
|
if (type <= BGP_LS_TLV_MAX &&
|
||||||
bgp_linkstate_tlv_infos[type].descr != NULL)
|
bgp_linkstate_tlv_infos[type].descr != NULL)
|
||||||
vty_out(vty, "%*s%s: ", indent, "",
|
vty_out(vty, "%*s%s: ", indent, "",
|
||||||
bgp_linkstate_tlv_infos[type].descr);
|
bgp_linkstate_tlv_infos[type].descr);
|
||||||
|
@ -197,7 +197,7 @@ enum bgp_linkstate_tlv {
|
|||||||
1251, /* draft-ietf-idr-bgpls-srv6-ext-08 */
|
1251, /* draft-ietf-idr-bgpls-srv6-ext-08 */
|
||||||
BGP_LS_TLV_SRV6_SID_STRUCTURE_TLV =
|
BGP_LS_TLV_SRV6_SID_STRUCTURE_TLV =
|
||||||
1252, /* draft-ietf-idr-bgpls-srv6-ext-08 */
|
1252, /* draft-ietf-idr-bgpls-srv6-ext-08 */
|
||||||
BGP_LS_TLV_MAX = 1253, /* max TLV value for table size*/
|
BGP_LS_TLV_MAX = 1252, /* max TLV value for table size*/
|
||||||
};
|
};
|
||||||
|
|
||||||
/* RFC7752 #3.2.1.4 IGP router-ID */
|
/* RFC7752 #3.2.1.4 IGP router-ID */
|
||||||
|
Loading…
Reference in New Issue
Block a user