Please switch it to poll(2) like ping6(8) is doing, there by side stepping the whole issue.
On Tue, Apr 22, 2014 at 09:33:50AM +0200, Otto Moerbeek wrote: > On Tue, Apr 22, 2014 at 02:57:54AM -0400, pe...@petermalone.org wrote: > > > Sure - I should have spotted that. > > Still not there. Please use the fact that calloc can multiply, you get > an overflow check for free. > > -Otto > > > > > Index: ping.c > > =================================================================== > > RCS file: /cvs/src/sbin/ping/ping.c,v > > retrieving revision 1.100 > > diff -u -r1.100 ping.c > > --- ping.c 24 Mar 2014 11:11:49 -0000 1.100 > > +++ ping.c 22 Apr 2014 06:55:03 -0000 > > @@ -188,7 +188,6 @@ > > socklen_t maxsizelen; > > const char *errstr; > > fd_set *fdmaskp; > > - size_t fdmasks; > > uid_t uid; > > u_int rtableid; > > > > @@ -507,9 +506,8 @@ > > if ((options & F_FLOOD) == 0) > > catcher(0); /* start things going */ > > > > - fdmasks = howmany(s+1, NFDBITS) * sizeof(fd_mask); > > - if ((fdmaskp = (fd_set *)malloc(fdmasks)) == NULL) > > - err(1, "malloc"); > > + if ((fdmaskp = calloc(1, howmany(s+1, NFDBITS) * sizeof(fd_mask))) > > == NULL) > > + err(1, "calloc"); > > > > for (;;) { > > struct sockaddr_in from; > > @@ -521,7 +519,6 @@ > > pinger(); > > timeout.tv_sec = 0; > > timeout.tv_usec = 10000; > > - memset(fdmaskp, 0, fdmasks); > > FD_SET(s, fdmaskp); > > if (select(s + 1, (fd_set *)fdmaskp, (fd_set *)NULL, > > (fd_set *)NULL, &timeout) < 1) > > > > > > Quoting Otto Moerbeek <o...@drijf.net>: > > > > >On Tue, Apr 22, 2014 at 12:45:25AM -0400, Peter Malone wrote: > > > > > >>Hi, > > >> > > >>malloc & memset can be replaced with calloc in ping.c. Please see below > > >>for > > >>patch details: > > > > > >Better rework this to get rid of fdmasks. > > > > > > -Otto > > > > > >> > > >>Index: ping.c > > >>=================================================================== > > >>RCS file: /cvs/src/sbin/ping/ping.c,v > > >>retrieving revision 1.100 > > >>diff -u -p -u -r1.100 ping.c > > >>--- ping.c 24 Mar 2014 11:11:49 -0000 1.100 > > >>+++ ping.c 22 Apr 2014 04:41:56 -0000 > > >>@@ -508,8 +508,8 @@ main(int argc, char *argv[]) > > >> catcher(0); /* start things going */ > > >> > > >> fdmasks = howmany(s+1, NFDBITS) * sizeof(fd_mask); > > >>- if ((fdmaskp = (fd_set *)malloc(fdmasks)) == NULL) > > >>- err(1, "malloc"); > > >>+ if ((fdmaskp = calloc(1, fdmasks)) == NULL) > > >>+ err(1, "calloc"); > > >> > > >> for (;;) { > > >> struct sockaddr_in from; > > >>@@ -521,7 +521,6 @@ main(int argc, char *argv[]) > > >> pinger(); > > >> timeout.tv_sec = 0; > > >> timeout.tv_usec = 10000; > > >>- memset(fdmaskp, 0, fdmasks); > > >> FD_SET(s, fdmaskp); > > >> if (select(s + 1, (fd_set *)fdmaskp, (fd_set *)NULL, > > >> (fd_set *)NULL, &timeout) < 1) > > >> > > > > > > > > > -- I'm not entirely sure you are real.