Skip to content

Commit e3c64ca

Browse files
committed
bugfix: avoid OOB access on systems where libpcap does support pcap_get_selectable_fd
1 parent 956f649 commit e3c64ca

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

bpfmon.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// $Id: bpfmon.c,v 2.48 2020/09/15 15:01:15 bbonev Exp $ {{{
1+
// $Id: bpfmon.c,v 2.49 2020/10/02 19:39:24 bbonev Exp $ {{{
22
// Copyright © 2015-2020 Boian Bonev (bbonev@ipacct.com)
33
//
44
// SPDX-License-Identifer: GPL-2.0-or-later
@@ -113,7 +113,7 @@ static char **drlevels=levels_utf8; // graph draw characters
113113
static int heartbeat=0;
114114
static char *sbps=" bytes per second ";
115115
static char *spps=" packets per second ";
116-
static char ver[]="$Revision: 2.48 $";
116+
static char ver[]="$Revision: 2.49 $";
117117
static int simplest=0; // use simplest console mode
118118
static int legend=1; // show legend in classic mode
119119
static int history=0; // show history in classic mode
@@ -988,7 +988,8 @@ int main(int ac,char **av) { // {{{
988988
FD_SET(STDIN_FILENO,&r);
989989
fdmax=STDIN_FILENO;
990990
if (source==PCAP) {
991-
FD_SET(pcfd,&r);
991+
if (pcfd>=0) // e.g. on Hurd libpcap does not support events via fd
992+
FD_SET(pcfd,&r);
992993
fdmax=mymax(fdmax,pcfd);
993994
}
994995
to.tv_sec=0;
@@ -1149,7 +1150,7 @@ int main(int ac,char **av) { // {{{
11491150
}
11501151
}
11511152
}
1152-
if (source==PCAP&&FD_ISSET(pcfd,&r))
1153+
if (pcfd<0||(source==PCAP&&FD_ISSET(pcfd,&r)))
11531154
pcap_dispatch(pc,10000,pc_cb,NULL);
11541155
}
11551156
if (toexit)

0 commit comments

Comments
 (0)