summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-08-09 19:36:00 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-08-09 19:36:00 +0000
commit4fecec7642d3cef00e1cbe278b6ce9993a65515e (patch)
tree8df322ca29260a0a127ad5124f8ec541d0d32458
parent51aaa8af993900c005ce0bdd17deb5e4f1d68e4e (diff)
Add some additional poll() error checking. Remove checks
for EAGAIN as that is not a possible poll() errno. suggestions & ok guenther@
-rw-r--r--sbin/dhclient/dhclient.c34
-rw-r--r--sbin/dhclient/dispatch.c45
2 files changed, 51 insertions, 28 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index fa2d9030a1e..a6f42c894f7 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.490 2017/08/08 17:20:09 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.491 2017/08/09 19:35:59 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -2137,14 +2137,19 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2)
while (quit == 0) {
pfd[0].fd = priv_ibuf->fd;
pfd[0].events = POLLIN;
- if ((nfds = poll(pfd, 1, INFTIM)) == -1) {
- if (errno != EINTR) {
- log_warn("poll error");
- quit = INTERNALSIG;
- }
+
+ nfds = poll(pfd, 1, INFTIM);
+ if (nfds == -1) {
+ if (errno == EINTR)
+ continue;
+ log_warn("priv_ibuf poll");
+ quit = INTERNALSIG;
+ continue;
+ }
+ if ((pfd[0].revents & (POLLERR | POLLHUP | POLLNVAL)) != 0) {
+ quit = INTERNALSIG;
continue;
}
-
if (nfds == 0 || (pfd[0].revents & POLLIN) == 0)
continue;
@@ -2153,7 +2158,6 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2)
quit = INTERNALSIG;
continue;
}
-
if (n == 0) {
/* Connection closed - other end should log message. */
quit = INTERNALSIG;
@@ -2516,7 +2520,7 @@ take_charge(struct interface_info *ifi, int routefd)
struct pollfd fds[1];
struct rt_msghdr rtm;
time_t start_time, cur_time;
- int retries;
+ int nfds, retries;
if (time(&start_time) == -1)
fatal("time");
@@ -2555,13 +2559,17 @@ take_charge(struct interface_info *ifi, int routefd)
}
fds[0].fd = routefd;
fds[0].events = POLLIN;
- if (poll(fds, 1, 3) == -1) {
- if (errno == EAGAIN || errno == EINTR)
+ nfds = poll(fds, 1, 3);
+ if (nfds == -1) {
+ if (errno == EINTR)
continue;
fatal("routefd poll");
}
- if ((fds[0].revents & (POLLIN | POLLHUP)) != 0)
- routehandler(ifi, routefd);
+ if ((fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) != 0)
+ fatalx("routed poll error");
+ if (nfds == 0 || (fds[0].revents & POLLIN) == 0)
+ continue;
+ routehandler(ifi, routefd);
}
}
diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c
index 9c77cbb7569..08d4d2b7a49 100644
--- a/sbin/dhclient/dispatch.c
+++ b/sbin/dhclient/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.135 2017/07/24 17:15:41 krw Exp $ */
+/* $OpenBSD: dispatch.c,v 1.136 2017/08/09 19:35:59 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -81,7 +81,7 @@ dispatch(struct interface_info *ifi, int routefd)
struct pollfd fds[3];
void (*func)(struct interface_info *);
time_t cur_time, howlong;
- int count, to_msec;
+ int nfds, to_msec;
while (quit == 0 || quit == SIGHUP) {
if (quit == SIGHUP) {
@@ -125,30 +125,45 @@ dispatch(struct interface_info *ifi, int routefd)
if (unpriv_ibuf->w.queued)
fds[2].events |= POLLOUT;
- count = poll(fds, 3, to_msec);
- if (count == -1) {
- if (errno == EAGAIN || errno == EINTR) {
+ nfds = poll(fds, 3, to_msec);
+ if (nfds == -1) {
+ if (errno == EINTR)
continue;
- } else {
- log_warn("poll");
- quit = INTERNALSIG;
- continue;
- }
+ log_warn("dispatch poll");
+ quit = INTERNALSIG;
+ continue;
+ }
+
+ if ((fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) != 0) {
+ log_warnx("bfdesc poll error");
+ quit = INTERNALSIG;
+ continue;
}
+ if ((fds[1].revents & (POLLERR | POLLHUP | POLLNVAL)) != 0) {
+ log_warnx("routefd poll error");
+ quit = INTERNALSIG;
+ continue;
+ }
+ if ((fds[2].revents & (POLLERR | POLLHUP | POLLNVAL)) != 0) {
+ log_warnx("unpriv_ibuf poll error");
+ quit = INTERNALSIG;
+ continue;
+ }
+
+ if (nfds == 0)
+ continue;
- if ((fds[0].revents & (POLLIN | POLLHUP)) != 0) {
+ if ((fds[0].revents & POLLIN) != 0) {
do {
packethandler(ifi);
} while (ifi->rbuf_offset < ifi->rbuf_len);
}
- if ((fds[1].revents & (POLLIN | POLLHUP)) != 0)
+ if ((fds[1].revents & POLLIN) != 0)
routehandler(ifi, routefd);
if ((fds[2].revents & POLLOUT) != 0)
flush_unpriv_ibuf("dispatch");
- if ((fds[2].revents & (POLLIN | POLLHUP)) != 0) {
- /* Pipe to [priv] closed. Assume it emitted error. */
+ if ((fds[2].revents & POLLIN) != 0)
quit = INTERNALSIG;
- }
}
if (quit != INTERNALSIG)