Download raw body.
bgpctl: fix mrt default file handling
On Thu, May 07, 2026 at 01:40:49PM +0200, Claudio Jeker wrote:
> bgpctl(8) has this in show mrt:
> file name Read the MRT dump from file name instead of using
> stdin.
>
> So if no file argument is passed to bgpctl then stdin should be used.
> I broke this when fixing a coverity report that something like
> bgpctl show mrt file a file b
> would leak a filedescriptor.
>
> Adjust the code to use STDIN_FILENO instead of -1 as initial value of
> res.mrtfd.
looks good, ok
>
> --
> :wq Claudio
>
> Index: parser.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/bgpctl/parser.c,v
> diff -u -p -r1.139 parser.c
> --- parser.c 4 Nov 2025 15:30:50 -0000 1.139
> +++ parser.c 6 May 2026 18:37:29 -0000
> @@ -489,7 +489,7 @@ parse(int argc, char *argv[])
>
> memset(&res, 0, sizeof(res));
> res.rtableid = getrtable();
> - res.mrtfd = -1;
> + res.mrtfd = STDIN_FILENO;
> TAILQ_INIT(&res.set);
>
> while (argc >= 0) {
> @@ -802,7 +802,7 @@ match_token(int argc, char *argv[], cons
> break;
> case FILENAME:
> if (word != NULL && wordlen > 0) {
> - if (res.mrtfd != -1)
> + if (res.mrtfd != STDIN_FILENO)
> errx(1, "mrt file already set");
> if ((res.mrtfd = open(word, O_RDONLY)) == -1) {
> /*
>
bgpctl: fix mrt default file handling