summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2022-01-14 13:49:32 +1100
committerDamien Miller <djm@mindrot.org>2022-01-14 14:09:38 +1100
commita1d42a6ce0398da3833bedf374ef2571af7fea50 (patch)
treef8807c7acc8d14658009af44c1ccb78ae6256b84 /openbsd-compat
parent976b9588b4b5babcaceec4767a241c11a67a5ccb (diff)
downloadopenssh-git-a1d42a6ce0398da3833bedf374ef2571af7fea50.tar.gz
fix edge case in poll(2) wrapper
Correct handling of select(2) exceptfds. These should only be consulted for POLLPRI flagged pfds and not unconditionally converted to POLLERR. with and ok dtucker@
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/bsd-poll.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/openbsd-compat/bsd-poll.c b/openbsd-compat/bsd-poll.c
index 8084776c..f8b427fc 100644
--- a/openbsd-compat/bsd-poll.c
+++ b/openbsd-compat/bsd-poll.c
@@ -33,8 +33,8 @@
/*
* A minimal implementation of ppoll(2), built on top of pselect(2).
*
- * Only supports POLLIN and POLLOUT flags in pfd.events, and POLLIN, POLLOUT
- * and POLLERR flags in revents.
+ * Only supports POLLIN, POLLOUT and POLLPRI flags in pfd.events and
+ * revents. Notably POLLERR, POLLHUP and POLLNVAL are not supported.
*
* Supports pfd.fd = -1 meaning "unused" although it's not standard.
*/
@@ -71,14 +71,12 @@ ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmoutp,
fd = fds[i].fd;
if (fd == -1)
continue;
- if (fds[i].events & POLLIN) {
+ if (fds[i].events & POLLIN)
FD_SET(fd, readfds);
- FD_SET(fd, exceptfds);
- }
- if (fds[i].events & POLLOUT) {
+ if (fds[i].events & POLLOUT)
FD_SET(fd, writefds);
+ if (fds[i].events & POLLPRI)
FD_SET(fd, exceptfds);
- }
}
ret = pselect(maxfd + 1, readfds, writefds, exceptfds, tmoutp, sigmask);
@@ -90,15 +88,12 @@ ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmoutp,
fds[i].revents = 0;
if (fd == -1)
continue;
- if (FD_ISSET(fd, readfds)) {
+ if (FD_ISSET(fd, readfds))
fds[i].revents |= POLLIN;
- }
- if (FD_ISSET(fd, writefds)) {
+ if (FD_ISSET(fd, writefds))
fds[i].revents |= POLLOUT;
- }
- if (FD_ISSET(fd, exceptfds)) {
- fds[i].revents |= POLLERR;
- }
+ if (FD_ISSET(fd, exceptfds))
+ fds[i].revents |= POLLPRI;
}
out: