Skip to content

Commit 1ce1c53

Browse files
authored
Merge pull request #13864 from pguibert6WIND/bgp_coverity_fix
Bgp coverity fix
2 parents 6ca6ae3 + bf11a19 commit 1ce1c53

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

bgpd/bgp_mplsvpn.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,14 +4023,21 @@ static void bgp_mplsvpn_nh_label_bind_send_nexthop_label(
40234023
}
40244024
p = &pfx_nh;
40254025
if (nh->nh_label) {
4026-
if (nh->nh_label->num_labels >
4027-
MPLS_MAX_LABELS - num_labels)
4028-
lsp_num_labels = MPLS_MAX_LABELS - num_labels;
4029-
else
4030-
lsp_num_labels = nh->nh_label->num_labels;
4026+
if (nh->nh_label->num_labels + 1 > MPLS_MAX_LABELS) {
4027+
/* label stack overflow. no label switching will be performed
4028+
*/
4029+
flog_err(EC_BGP_LABEL,
4030+
"%s [Error] BGP label %u->%u to %pFX, forged label stack too big: %u. Abort LSP installation",
4031+
bmnc->bgp_vpn->name_pretty,
4032+
bmnc->new_label, bmnc->orig_label,
4033+
&bmnc->nexthop,
4034+
nh->nh_label->num_labels + 1);
4035+
return;
4036+
}
4037+
lsp_num_labels = nh->nh_label->num_labels;
40314038
for (i = 0; i < lsp_num_labels; i++)
40324039
label[num_labels + i] = nh->nh_label->label[i];
4033-
num_labels += lsp_num_labels;
4040+
num_labels = lsp_num_labels;
40344041
}
40354042
label[num_labels] = bmnc->orig_label;
40364043
num_labels += 1;
@@ -4239,15 +4246,13 @@ void bgp_mplsvpn_nh_label_bind_register_local_label(struct bgp *bgp,
42394246
return;
42404247

42414248
bgp_mplsvpn_path_nh_label_bind_unlink(pi);
4242-
if (bmnc) {
4243-
/* updates NHT pi list reference */
4244-
LIST_INSERT_HEAD(&(bmnc->paths), pi,
4245-
mplsvpn.bmnc.nh_label_bind_thread);
4246-
pi->mplsvpn.bmnc.nh_label_bind_cache = bmnc;
4247-
pi->mplsvpn.bmnc.nh_label_bind_cache->path_count++;
4248-
SET_FLAG(pi->flags, BGP_PATH_MPLSVPN_NH_LABEL_BIND);
4249-
bmnc->last_update = monotime(NULL);
4250-
}
4249+
4250+
/* updates NHT pi list reference */
4251+
LIST_INSERT_HEAD(&(bmnc->paths), pi, mplsvpn.bmnc.nh_label_bind_thread);
4252+
pi->mplsvpn.bmnc.nh_label_bind_cache = bmnc;
4253+
pi->mplsvpn.bmnc.nh_label_bind_cache->path_count++;
4254+
SET_FLAG(pi->flags, BGP_PATH_MPLSVPN_NH_LABEL_BIND);
4255+
bmnc->last_update = monotime(NULL);
42514256

42524257
/* Add or update the selected nexthop */
42534258
if (!bmnc->nh)

0 commit comments

Comments
 (0)