Skip to content

Commit fdddac1

Browse files
committed
bgpd: Add a safety guard against uint64 max value if TLV length is 0
When the TLV length is less than 8 (which should never happen, because TLV MUST not be propagated if no Next-next hops exist, but hack3rs don't care), we have count 0, and then subtracting results with the very huge unsigned number. Prevent this from happening. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
1 parent a6244e5 commit fdddac1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

bgpd/bgp_nhc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ uint64_t bgp_nhc_nnhn_count(struct bgp_nhc *nhc)
8787

8888
for (tlv = nhc->tlvs; tlv; tlv = tlv->next) {
8989
if (tlv->code == BGP_ATTR_NHC_TLV_NNHN) {
90-
/* BGP Identifier is always 4-bytes (yet...).
91-
* -1 is to exclude the next-hop BGP ID.
90+
/* BGP Identifier is always 4-bytes (yet...) */
91+
count = tlv->length / IPV4_MAX_BYTELEN;
92+
if (count <= 1)
93+
return 0;
94+
95+
/* -1 is to exclude the next-hop BGP ID.
9296
* We care only about Next-next hops here.
9397
*/
94-
count = (tlv->length / IPV4_MAX_BYTELEN) - 1;
95-
break;
98+
return count - 1;
9699
}
97100
}
98101

99-
return count;
102+
return 0;
100103
}

0 commit comments

Comments
 (0)