]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: replace select() with ppoll(), including converting
authorderaadt@openbsd.org <deraadt@openbsd.org>
Sat, 13 Nov 2021 21:14:13 +0000 (21:14 +0000)
committerDamien Miller <djm@mindrot.org>
Wed, 17 Nov 2021 22:09:59 +0000 (09:09 +1100)
timeval's to timespec's to make things easier. back and forth and ok; djm

OpenBSD-Commit-ID: 89d3b23c60875da919e7820f9de6213286ffbec9

misc.c
misc.h
packet.c

diff --git a/misc.c b/misc.c
index 0134d69492e404269bae32eebf4c6f52974a96f9..f541055c185edc933fdfceb77064ff2665a982ba 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.170 2021/09/26 14:01:03 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.171 2021/11/13 21:14:13 deraadt Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  * Copyright (c) 2005-2020 Damien Miller.  All rights reserved.
@@ -1616,12 +1616,12 @@ ms_subtract_diff(struct timeval *start, int *ms)
 }
 
 void
-ms_to_timeval(struct timeval *tv, int ms)
+ms_to_timespec(struct timespec *ts, int ms)
 {
        if (ms < 0)
                ms = 0;
-       tv->tv_sec = ms / 1000;
-       tv->tv_usec = (ms % 1000) * 1000;
+       ts->tv_sec = ms / 1000;
+       ts->tv_nsec = (ms % 1000) * 1000 * 1000;
 }
 
 void
diff --git a/misc.h b/misc.h
index 2e2dca54bf45d8c16b2301998207f3deb385209c..2e1b5fecaa017912ea3d7a5e92aaa1103c80cce3 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.98 2021/08/09 23:47:44 djm Exp $ */
+/* $OpenBSD: misc.h,v 1.99 2021/11/13 21:14:13 deraadt Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -82,7 +82,7 @@ void   xextendf(char **s, const char *sep, const char *fmt, ...)
     __attribute__((__format__ (printf, 3, 4))) __attribute__((__nonnull__ (3)));
 void    sanitise_stdfd(void);
 void    ms_subtract_diff(struct timeval *, int *);
-void    ms_to_timeval(struct timeval *, int);
+void    ms_to_timespec(struct timespec *, int);
 void    monotime_ts(struct timespec *);
 void    monotime_tv(struct timeval *);
 time_t  monotime(void);
index 9908994182f440cc4a08c1935f7551dca51a4fef..10a6c370420ffdf3f54b064cb5648f01eac293e2 100644 (file)
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.301 2021/07/16 09:00:23 djm Exp $ */
+/* $OpenBSD: packet.c,v 1.302 2021/11/13 21:14:13 deraadt Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1325,17 +1325,13 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
 {
        struct session_state *state = ssh->state;
        int len, r, ms_remain;
-       fd_set *setp;
+       struct pollfd pfd;
        char buf[8192];
-       struct timeval timeout, start, *timeoutp = NULL;
+       struct timeval start;
+       struct timespec timespec, *timespecp = NULL;
 
        DBG(debug("packet_read()"));
 
-       setp = calloc(howmany(state->connection_in + 1,
-           NFDBITS), sizeof(fd_mask));
-       if (setp == NULL)
-               return SSH_ERR_ALLOC_FAIL;
-
        /*
         * Since we are blocking, ensure that all written packets have
         * been sent.
@@ -1356,22 +1352,20 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
                 * Otherwise, wait for some data to arrive, add it to the
                 * buffer, and try again.
                 */
-               memset(setp, 0, howmany(state->connection_in + 1,
-                   NFDBITS) * sizeof(fd_mask));
-               FD_SET(state->connection_in, setp);
+               pfd.fd = state->connection_in;
+               pfd.events = POLLIN;
 
                if (state->packet_timeout_ms > 0) {
                        ms_remain = state->packet_timeout_ms;
-                       timeoutp = &timeout;
+                       timespecp = &timespec;
                }
                /* Wait for some data to arrive. */
                for (;;) {
                        if (state->packet_timeout_ms > 0) {
-                               ms_to_timeval(&timeout, ms_remain);
+                               ms_to_timespec(&timespec, ms_remain);
                                monotime_tv(&start);
                        }
-                       if ((r = select(state->connection_in + 1, setp,
-                           NULL, NULL, timeoutp)) >= 0)
+                       if ((r = ppoll(&pfd, 1, timespecp, NULL)) >= 0)
                                break;
                        if (errno != EAGAIN && errno != EINTR &&
                            errno != EWOULDBLOCK) {
@@ -1406,7 +1400,6 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
                        goto out;
        }
  out:
-       free(setp);
        return r;
 }
 
@@ -1986,35 +1979,28 @@ ssh_packet_write_poll(struct ssh *ssh)
 int
 ssh_packet_write_wait(struct ssh *ssh)
 {
-       fd_set *setp;
        int ret, r, ms_remain = 0;
-       struct timeval start, timeout, *timeoutp = NULL;
+       struct timeval start;
+       struct timespec timespec, *timespecp = NULL;
        struct session_state *state = ssh->state;
+       struct pollfd pfd;
 
-       setp = calloc(howmany(state->connection_out + 1,
-           NFDBITS), sizeof(fd_mask));
-       if (setp == NULL)
-               return SSH_ERR_ALLOC_FAIL;
-       if ((r = ssh_packet_write_poll(ssh)) != 0) {
-               free(setp);
+       if ((r = ssh_packet_write_poll(ssh)) != 0)
                return r;
-       }
        while (ssh_packet_have_data_to_write(ssh)) {
-               memset(setp, 0, howmany(state->connection_out + 1,
-                   NFDBITS) * sizeof(fd_mask));
-               FD_SET(state->connection_out, setp);
+               pfd.fd = state->connection_out;
+               pfd.events = POLLOUT;
 
                if (state->packet_timeout_ms > 0) {
                        ms_remain = state->packet_timeout_ms;
-                       timeoutp = &timeout;
+                       timespecp = &timespec;
                }
                for (;;) {
                        if (state->packet_timeout_ms > 0) {
-                               ms_to_timeval(&timeout, ms_remain);
+                               ms_to_timespec(&timespec, ms_remain);
                                monotime_tv(&start);
                        }
-                       if ((ret = select(state->connection_out + 1,
-                           NULL, setp, NULL, timeoutp)) >= 0)
+                       if ((ret = ppoll(&pfd, 1, timespecp, NULL)) >= 0)
                                break;
                        if (errno != EAGAIN && errno != EINTR &&
                            errno != EWOULDBLOCK)
@@ -2027,16 +2013,11 @@ ssh_packet_write_wait(struct ssh *ssh)
                                break;
                        }
                }
-               if (ret == 0) {
-                       free(setp);
+               if (ret == 0)
                        return SSH_ERR_CONN_TIMEOUT;
-               }
-               if ((r = ssh_packet_write_poll(ssh)) != 0) {
-                       free(setp);
+               if ((r = ssh_packet_write_poll(ssh)) != 0)
                        return r;
-               }
        }
-       free(setp);
        return 0;
 }