Skip to content

Commit 766eec1

Browse files
committed
bgpd: Ensure that bgp open message stream has enough data to read
If a operator receives an invalid packet that is of insufficient size then it is possible for BGP to assert during reading of the packet instead of gracefully resetting the connection with the peer. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
1 parent 8d133f9 commit 766eec1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bgpd/bgp_packet.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,8 +1386,27 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size)
13861386
|| CHECK_FLAG(peer->flags, PEER_FLAG_EXTENDED_OPT_PARAMS)) {
13871387
uint8_t opttype;
13881388

1389+
if (STREAM_READABLE(peer->curr) < 1) {
1390+
flog_err(
1391+
EC_BGP_PKT_OPEN,
1392+
"%s: stream does not have enough bytes for extended optional parameters",
1393+
peer->host);
1394+
bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR,
1395+
BGP_NOTIFY_OPEN_MALFORMED_ATTR);
1396+
return BGP_Stop;
1397+
}
1398+
13891399
opttype = stream_getc(peer->curr);
13901400
if (opttype == BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH) {
1401+
if (STREAM_READABLE(peer->curr) < 2) {
1402+
flog_err(
1403+
EC_BGP_PKT_OPEN,
1404+
"%s: stream does not have enough bytes to read the extended optional parameters optlen",
1405+
peer->host);
1406+
bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR,
1407+
BGP_NOTIFY_OPEN_MALFORMED_ATTR);
1408+
return BGP_Stop;
1409+
}
13911410
optlen = stream_getw(peer->curr);
13921411
SET_FLAG(peer->sflags,
13931412
PEER_STATUS_EXT_OPT_PARAMS_LENGTH);

0 commit comments

Comments
 (0)