Skip to content

Commit 553f44e

Browse files
committed
bgpd: Fix infinite loop in MRT route dump for oversized paths
This is a complete fix for CVE-2016-4049. Fixes: 246556b ("bgpd: Fix buffer overflow error in bgp_dump_routes_func") Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
1 parent ef48338 commit 553f44e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

bgpd/bgp_dump.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,29 @@ bgp_dump_route_node_record(int afi, struct bgp_dest *dest,
377377
+ BGP_DUMP_MSG_HEADER
378378
+ BGP_DUMP_HEADER_SIZE) {
379379
stream_set_endp(obuf, endp);
380+
if (entry_count == 0) {
381+
/* A single path's encoding exceeds the
382+
* per-record cap. Skip it so the caller's
383+
* while (path) loop makes forward progress.
384+
*/
385+
flog_warn(EC_BGP_DUMP,
386+
"%s: skipping oversized path for %pFX from peer %s",
387+
__func__, p, path->peer->host);
388+
path = path->next;
389+
}
380390
break;
381391
}
382392

383393
entry_count++;
384394
endp = cur_endp;
385395
}
386396

397+
/* Skip emitting a zero-entry record: some MRT parsers treat them as
398+
* corrupt.
399+
*/
400+
if (entry_count == 0)
401+
return path;
402+
387403
/* Overwrite the entry count, now that we know the right number */
388404
stream_putw_at(obuf, sizep, entry_count);
389405

0 commit comments

Comments
 (0)