summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>2014-12-02 19:39:16 +0000
committerderaadt <>2014-12-02 19:39:16 +0000
commitc8143494d57c2153f018143c0a4c9f301036495c (patch)
tree76e9b81af362bf620cdb122dd89bd349c0a01709 /src
parent28c71cd24b7756816d29f6704f72acde61ad5a8c (diff)
downloadopenbsd-c8143494d57c2153f018143c0a4c9f301036495c.tar.gz
openbsd-c8143494d57c2153f018143c0a4c9f301036495c.tar.bz2
openbsd-c8143494d57c2153f018143c0a4c9f301036495c.zip
Conversion of braindead select() path to braindead poll() path.
Also looked at by bcook
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/openssl/ocsp.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/usr.bin/openssl/ocsp.c b/src/usr.bin/openssl/ocsp.c
index bdc224d8bc..3cf85d4d2c 100644
--- a/src/usr.bin/openssl/ocsp.c
+++ b/src/usr.bin/openssl/ocsp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp.c,v 1.1 2014/08/26 17:47:24 jsing Exp $ */ 1/* $OpenBSD: ocsp.c,v 1.2 2014/12/02 19:39:16 deraadt Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -57,12 +57,13 @@
57 */ 57 */
58#ifndef OPENSSL_NO_OCSP 58#ifndef OPENSSL_NO_OCSP
59 59
60#include <sys/select.h> 60#include <sys/types.h>
61 61
62#include <stdio.h> 62#include <stdio.h>
63#include <stdlib.h> 63#include <stdlib.h>
64#include <limits.h> 64#include <limits.h>
65#include <string.h> 65#include <string.h>
66#include <poll.h>
66#include <time.h> 67#include <time.h>
67 68
68/* Needs to be included before the openssl headers! */ 69/* Needs to be included before the openssl headers! */
@@ -1102,8 +1103,7 @@ query_responder(BIO * err, BIO * cbio, char *path,
1102 int i; 1103 int i;
1103 OCSP_REQ_CTX *ctx = NULL; 1104 OCSP_REQ_CTX *ctx = NULL;
1104 OCSP_RESPONSE *rsp = NULL; 1105 OCSP_RESPONSE *rsp = NULL;
1105 fd_set confds; 1106 struct pollfd pfd[1];
1106 struct timeval tv;
1107 1107
1108 if (req_timeout != -1) 1108 if (req_timeout != -1)
1109 BIO_set_nbio(cbio, 1); 1109 BIO_set_nbio(cbio, 1);
@@ -1119,15 +1119,17 @@ query_responder(BIO * err, BIO * cbio, char *path,
1119 goto err; 1119 goto err;
1120 } 1120 }
1121 if (req_timeout != -1 && rv <= 0) { 1121 if (req_timeout != -1 && rv <= 0) {
1122 FD_ZERO(&confds); 1122 pfd[0].fd = fd;
1123 FD_SET(fd, &confds); 1123 pfd[0].events = POLLOUT;
1124 tv.tv_usec = 0; 1124 rv = poll(pfd, 1, req_timeout * 1000);
1125 tv.tv_sec = req_timeout;
1126 rv = select(fd + 1, NULL, &confds, NULL, &tv);
1127 if (rv == 0) { 1125 if (rv == 0) {
1128 BIO_puts(err, "Timeout on connect\n"); 1126 BIO_puts(err, "Timeout on connect\n");
1129 return NULL; 1127 return NULL;
1130 } 1128 }
1129 if (rv == -1) {
1130 BIO_puts(err, "Poll error\n");
1131 return NULL;
1132 }
1131 } 1133 }
1132 ctx = OCSP_sendreq_new(cbio, path, NULL, -1); 1134 ctx = OCSP_sendreq_new(cbio, path, NULL, -1);
1133 if (!ctx) 1135 if (!ctx)
@@ -1148,24 +1150,22 @@ query_responder(BIO * err, BIO * cbio, char *path,
1148 break; 1150 break;
1149 if (req_timeout == -1) 1151 if (req_timeout == -1)
1150 continue; 1152 continue;
1151 FD_ZERO(&confds); 1153 pfd[0].fd = fd;
1152 FD_SET(fd, &confds);
1153 tv.tv_usec = 0;
1154 tv.tv_sec = req_timeout;
1155 if (BIO_should_read(cbio)) 1154 if (BIO_should_read(cbio))
1156 rv = select(fd + 1, &confds, NULL, NULL, &tv); 1155 pfd[0].events = POLLIN;
1157 else if (BIO_should_write(cbio)) 1156 else if (BIO_should_write(cbio))
1158 rv = select(fd + 1, NULL, &confds, NULL, &tv); 1157 pfd[0].events = POLLOUT;
1159 else { 1158 else {
1160 BIO_puts(err, "Unexpected retry condition\n"); 1159 BIO_puts(err, "Unexpected retry condition\n");
1161 goto err; 1160 goto err;
1162 } 1161 }
1162 rv = poll(pfd, 1, req_timeout * 1000);
1163 if (rv == 0) { 1163 if (rv == 0) {
1164 BIO_puts(err, "Timeout on request\n"); 1164 BIO_puts(err, "Timeout on request\n");
1165 break; 1165 break;
1166 } 1166 }
1167 if (rv == -1) { 1167 if (rv == -1 || (pfd[0].revents & (POLLERR|POLLNVAL))) {
1168 BIO_puts(err, "Select error\n"); 1168 BIO_puts(err, "Poll error\n");
1169 break; 1169 break;
1170 } 1170 }
1171 } 1171 }