From 6f5388d11ca7552025496dc1e465ad003e94f27e Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Tue, 2 Dec 2014 19:44:49 +0000 Subject: convert select() to poll(). This is one of the most complicated conversions in the tree, because the original code is very rotten and fragile. Please test and report any failures. Assistance from millert, bcook, and jsing. --- src/usr.bin/openssl/s_server.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/usr.bin/openssl/s_server.c') diff --git a/src/usr.bin/openssl/s_server.c b/src/usr.bin/openssl/s_server.c index 1e6f85f9fb..b3cdb30a61 100644 --- a/src/usr.bin/openssl/s_server.c +++ b/src/usr.bin/openssl/s_server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_server.c,v 1.6 2014/11/06 14:50:12 jsing Exp $ */ +/* $OpenBSD: s_server.c,v 1.7 2014/12/02 19:44:49 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -148,7 +148,6 @@ #include #include -#include #include #include @@ -158,6 +157,7 @@ #include #include #include +#include #include "apps.h" @@ -1279,14 +1279,12 @@ static int sv_body(char *hostname, int s, unsigned char *context) { char *buf = NULL; - fd_set readfds; - int ret = 1, width; + int ret = 1; int k, i; unsigned long l; SSL *con = NULL; BIO *sbio; struct timeval timeout; - struct timeval *timeoutp; if ((buf = malloc(bufsize)) == NULL) { BIO_printf(bio_err, "out of memory\n"); @@ -1366,35 +1364,45 @@ sv_body(char *hostname, int s, unsigned char *context) SSL_set_tlsext_debug_arg(con, bio_s_out); } - width = s + 1; for (;;) { int read_from_terminal; int read_from_sslcon; + struct pollfd pfd[2]; + int ptimeout; read_from_terminal = 0; read_from_sslcon = SSL_pending(con); if (!read_from_sslcon) { - FD_ZERO(&readfds); - FD_SET(fileno(stdin), &readfds); - FD_SET(s, &readfds); + pfd[0].fd = fileno(stdin); + pfd[0].events = POLLIN; + pfd[1].fd = s; + pfd[1].events = POLLIN; + if ((SSL_version(con) == DTLS1_VERSION) && DTLSv1_get_timeout(con, &timeout)) - timeoutp = &timeout; + ptimeout = timeout.tv_sec * 1000 + + timeout.tv_usec / 1000; else - timeoutp = NULL; + ptimeout = -1; - i = select(width, &readfds, NULL, NULL, timeoutp); + i = poll(pfd, 2, ptimeout); if ((SSL_version(con) == DTLS1_VERSION) && DTLSv1_handle_timeout(con) > 0) { BIO_printf(bio_err, "TIMEOUT occured\n"); } if (i <= 0) continue; - if (FD_ISSET(fileno(stdin), &readfds)) + if (pfd[0].revents) { + if ((pfd[0].revents & (POLLERR|POLLNVAL))) + continue; read_from_terminal = 1; - if (FD_ISSET(s, &readfds)) + } + if (pfd[1].revents) { + if ((pfd[1].revents & (POLLERR|POLLNVAL))) + continue; read_from_sslcon = 1; + } } if (read_from_terminal) { if (s_crlf) { -- cgit v1.2.3-55-g6feb