Skip to content

Commit 7212a1e

Browse files
committed
zebra: fix heap overflow and guard inconsistency in SRv6 nexthop resolution
1 parent f7e84eb commit 7212a1e

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

lib/nexthop.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,12 @@ void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *segs,
716716
XCALLOC(MTYPE_NH_SRV6,
717717
sizeof(struct seg6_seg_stack) +
718718
num_segs * sizeof(struct in6_addr));
719+
} else if (num_segs > nexthop->nh_srv6->seg6_segs->num_segs) {
720+
nexthop->nh_srv6->seg6_segs =
721+
XREALLOC(MTYPE_NH_SRV6,
722+
nexthop->nh_srv6->seg6_segs,
723+
sizeof(struct seg6_seg_stack) +
724+
num_segs * sizeof(struct in6_addr));
719725
}
720726

721727
nexthop->nh_srv6->seg6_segs->num_segs = num_segs;

zebra/zebra_nhg.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,9 +1960,9 @@ static struct nexthop *nexthop_set_resolved(afi_t afi, const struct nexthop *new
19601960
nexthop_add_labels(resolved_hop, label_type, num_labels,
19611961
labels);
19621962

1963-
/* Copy SRv6 info from the resolved route's nexthop first, then
1964-
* overlay any SRv6 info from the parent nexthop (consistent with
1965-
* how MPLS labels are stacked above).
1963+
/* Copy SRv6 info from the resolved route's nexthop (newhop) if
1964+
* present; if the parent nexthop also carries SRv6 info, its
1965+
* value takes precedence and replaces the resolver's.
19661966
*/
19671967
if (newhop->nh_srv6) {
19681968
if (newhop->nh_srv6->seg6local_action !=
@@ -1989,7 +1989,9 @@ static struct nexthop *nexthop_set_resolved(afi_t afi, const struct nexthop *new
19891989
->seg6local_action,
19901990
&nexthop->nh_srv6
19911991
->seg6local_ctx);
1992-
if (nexthop->nh_srv6->seg6_segs)
1992+
if (nexthop->nh_srv6->seg6_segs &&
1993+
nexthop->nh_srv6->seg6_segs->num_segs &&
1994+
!sid_zero(nexthop->nh_srv6->seg6_segs))
19931995
nexthop_add_srv6_seg6(resolved_hop, &nexthop->nh_srv6->seg6_segs->seg[0],
19941996
nexthop->nh_srv6->seg6_segs->num_segs,
19951997
nexthop->nh_srv6->seg6_segs->encap_behavior);

0 commit comments

Comments
 (0)