summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/s_server.c
diff options
context:
space:
mode:
authorderaadt <>2014-12-02 19:44:49 +0000
committerderaadt <>2014-12-02 19:44:49 +0000
commit6f5388d11ca7552025496dc1e465ad003e94f27e (patch)
tree6002058f0b7accfb8746cc5c4022e1bd924d4eea /src/usr.bin/openssl/s_server.c
parentc8143494d57c2153f018143c0a4c9f301036495c (diff)
downloadopenbsd-6f5388d11ca7552025496dc1e465ad003e94f27e.tar.gz
openbsd-6f5388d11ca7552025496dc1e465ad003e94f27e.tar.bz2
openbsd-6f5388d11ca7552025496dc1e465ad003e94f27e.zip
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.
Diffstat (limited to 'src/usr.bin/openssl/s_server.c')
-rw-r--r--src/usr.bin/openssl/s_server.c36
1 files changed, 22 insertions, 14 deletions
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 @@
1/* $OpenBSD: s_server.c,v 1.6 2014/11/06 14:50:12 jsing Exp $ */ 1/* $OpenBSD: s_server.c,v 1.7 2014/12/02 19:44:49 deraadt Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -148,7 +148,6 @@
148 148
149#include <sys/types.h> 149#include <sys/types.h>
150#include <sys/ioctl.h> 150#include <sys/ioctl.h>
151#include <sys/select.h>
152#include <sys/socket.h> 151#include <sys/socket.h>
153 152
154#include <assert.h> 153#include <assert.h>
@@ -158,6 +157,7 @@
158#include <limits.h> 157#include <limits.h>
159#include <string.h> 158#include <string.h>
160#include <unistd.h> 159#include <unistd.h>
160#include <poll.h>
161 161
162#include "apps.h" 162#include "apps.h"
163 163
@@ -1279,14 +1279,12 @@ static int
1279sv_body(char *hostname, int s, unsigned char *context) 1279sv_body(char *hostname, int s, unsigned char *context)
1280{ 1280{
1281 char *buf = NULL; 1281 char *buf = NULL;
1282 fd_set readfds; 1282 int ret = 1;
1283 int ret = 1, width;
1284 int k, i; 1283 int k, i;
1285 unsigned long l; 1284 unsigned long l;
1286 SSL *con = NULL; 1285 SSL *con = NULL;
1287 BIO *sbio; 1286 BIO *sbio;
1288 struct timeval timeout; 1287 struct timeval timeout;
1289 struct timeval *timeoutp;
1290 1288
1291 if ((buf = malloc(bufsize)) == NULL) { 1289 if ((buf = malloc(bufsize)) == NULL) {
1292 BIO_printf(bio_err, "out of memory\n"); 1290 BIO_printf(bio_err, "out of memory\n");
@@ -1366,35 +1364,45 @@ sv_body(char *hostname, int s, unsigned char *context)
1366 SSL_set_tlsext_debug_arg(con, bio_s_out); 1364 SSL_set_tlsext_debug_arg(con, bio_s_out);
1367 } 1365 }
1368 1366
1369 width = s + 1;
1370 for (;;) { 1367 for (;;) {
1371 int read_from_terminal; 1368 int read_from_terminal;
1372 int read_from_sslcon; 1369 int read_from_sslcon;
1370 struct pollfd pfd[2];
1371 int ptimeout;
1373 1372
1374 read_from_terminal = 0; 1373 read_from_terminal = 0;
1375 read_from_sslcon = SSL_pending(con); 1374 read_from_sslcon = SSL_pending(con);
1376 1375
1377 if (!read_from_sslcon) { 1376 if (!read_from_sslcon) {
1378 FD_ZERO(&readfds); 1377 pfd[0].fd = fileno(stdin);
1379 FD_SET(fileno(stdin), &readfds); 1378 pfd[0].events = POLLIN;
1380 FD_SET(s, &readfds); 1379 pfd[1].fd = s;
1380 pfd[1].events = POLLIN;
1381
1381 if ((SSL_version(con) == DTLS1_VERSION) && 1382 if ((SSL_version(con) == DTLS1_VERSION) &&
1382 DTLSv1_get_timeout(con, &timeout)) 1383 DTLSv1_get_timeout(con, &timeout))
1383 timeoutp = &timeout; 1384 ptimeout = timeout.tv_sec * 1000 +
1385 timeout.tv_usec / 1000;
1384 else 1386 else
1385 timeoutp = NULL; 1387 ptimeout = -1;
1386 1388
1387 i = select(width, &readfds, NULL, NULL, timeoutp); 1389 i = poll(pfd, 2, ptimeout);
1388 1390
1389 if ((SSL_version(con) == DTLS1_VERSION) && DTLSv1_handle_timeout(con) > 0) { 1391 if ((SSL_version(con) == DTLS1_VERSION) && DTLSv1_handle_timeout(con) > 0) {
1390 BIO_printf(bio_err, "TIMEOUT occured\n"); 1392 BIO_printf(bio_err, "TIMEOUT occured\n");
1391 } 1393 }
1392 if (i <= 0) 1394 if (i <= 0)
1393 continue; 1395 continue;
1394 if (FD_ISSET(fileno(stdin), &readfds)) 1396 if (pfd[0].revents) {
1397 if ((pfd[0].revents & (POLLERR|POLLNVAL)))
1398 continue;
1395 read_from_terminal = 1; 1399 read_from_terminal = 1;
1396 if (FD_ISSET(s, &readfds)) 1400 }
1401 if (pfd[1].revents) {
1402 if ((pfd[1].revents & (POLLERR|POLLNVAL)))
1403 continue;
1397 read_from_sslcon = 1; 1404 read_from_sslcon = 1;
1405 }
1398 } 1406 }
1399 if (read_from_terminal) { 1407 if (read_from_terminal) {
1400 if (s_crlf) { 1408 if (s_crlf) {