Skip to content

Commit 3e46b43

Browse files
committed
bgpd: Ensure FRR has enough data to read 2 bytes in peek_for_as4_capability
In peek_for_as4_capability the code is checking that the stream has at least 2 bytes to read ( the opt_type and the opt_length ). However if BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(peer) is configured then FRR is reading 3 bytes. Which is not good since the packet could be badly formated. Ensure that FRR has the appropriate data length to read the data. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
1 parent 5ae9644 commit 3e46b43

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

bgpd/bgp_open.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,15 +1185,30 @@ as_t peek_for_as4_capability(struct peer *peer, uint16_t length)
11851185
uint8_t opt_type;
11861186
uint16_t opt_length;
11871187

1188-
/* Check the length. */
1189-
if (stream_get_getp(s) + 2 > end)
1188+
/* Ensure we can read the option type */
1189+
if (stream_get_getp(s) + 1 > end)
11901190
goto end;
11911191

1192-
/* Fetch option type and length. */
1192+
/* Fetch the option type */
11931193
opt_type = stream_getc(s);
1194-
opt_length = BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(peer)
1195-
? stream_getw(s)
1196-
: stream_getc(s);
1194+
1195+
/*
1196+
* Check the length and fetch the opt_length
1197+
* If the peer is BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(peer)
1198+
* then we do a getw which is 2 bytes. So we need to
1199+
* ensure that we can read that as well
1200+
*/
1201+
if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(peer)) {
1202+
if (stream_get_getp(s) + 2 > end)
1203+
goto end;
1204+
1205+
opt_length = stream_getw(s);
1206+
} else {
1207+
if (stream_get_getp(s) + 1 > end)
1208+
goto end;
1209+
1210+
opt_length = stream_getc(s);
1211+
}
11971212

11981213
/* Option length check. */
11991214
if (stream_get_getp(s) + opt_length > end)

0 commit comments

Comments
 (0)