summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2014-10-29 04:39:02 +0000
committerderaadt <deraadt@openbsd.org>2014-10-29 04:39:02 +0000
commit12c656704fc3ae944f3671054da1f7bf43a4be50 (patch)
tree263118c7d3408a9e74c73f1ed5326179c4f2e7fe
parentAdd prototypes for xdr_{accepted,rejected}_reply() and svcudp_enablecache() (diff)
downloadwireguard-openbsd-12c656704fc3ae944f3671054da1f7bf43a4be50.tar.xz
wireguard-openbsd-12c656704fc3ae944f3671054da1f7bf43a4be50.zip
use poll() instead of the select malloc/free dance which was used to
avoid fd_set overflows. Back when I was young, I fixed these throughout the tree, and the world continued on ignoring the issue... The malloc/free dance was used because poll() was not very portable yet. Now poll() is commonplace, and we should use this safer API. ok guenther millert
-rw-r--r--usr.sbin/cron/cron.c15
-rw-r--r--usr.sbin/cron/externs.h3
2 files changed, 8 insertions, 10 deletions
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index 08aba72c485..e3d39778ff7 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cron.c,v 1.44 2013/04/17 15:58:45 deraadt Exp $ */
+/* $OpenBSD: cron.c,v 1.45 2014/10/29 04:39:02 deraadt Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@@ -379,17 +379,15 @@ cron_sleep(time_t target) {
struct timeval t1, t2, tv;
struct sockaddr_un s_un;
socklen_t sunlen;
- static fd_set *fdsr;
+ static struct pollfd pfd[1];
gettimeofday(&t1, NULL);
t1.tv_sec += GMToff;
tv.tv_sec = (target * SECONDS_PER_MINUTE - t1.tv_sec) + 1;
tv.tv_usec = 0;
- if (fdsr == NULL) {
- fdsr = (fd_set *)calloc(howmany(cronSock + 1, NFDBITS),
- sizeof(fd_mask));
- }
+ pfd[0].fd = cronSock;
+ pfd[0].events = POLLIN;
while (timerisset(&tv) && tv.tv_sec < 65) {
Debug(DSCH, ("[%ld] Target time=%lld, sec-to-wait=%lld\n",
@@ -397,10 +395,9 @@ cron_sleep(time_t target) {
(long long)tv.tv_sec))
poke = RELOAD_CRON | RELOAD_AT;
- if (fdsr)
- FD_SET(cronSock, fdsr);
+
/* Sleep until we time out, get a poke, or get a signal. */
- nfds = select(cronSock + 1, fdsr, NULL, NULL, &tv);
+ nfds = poll(pfd, 1, tv.tv_sec * 1000 + tv.tv_usec / 1000);
if (nfds == 0)
break; /* timer expired */
if (nfds == -1 && errno != EINTR)
diff --git a/usr.sbin/cron/externs.h b/usr.sbin/cron/externs.h
index 310b738767f..c8c3c113743 100644
--- a/usr.sbin/cron/externs.h
+++ b/usr.sbin/cron/externs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: externs.h,v 1.11 2013/04/17 15:58:45 deraadt Exp $ */
+/* $OpenBSD: externs.h,v 1.12 2014/10/29 04:39:02 deraadt Exp $ */
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
@@ -50,6 +50,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <poll.h>
#include <unistd.h>
#include <utime.h>