The attached patch makes the problem go away.

The method of solution is simple and obvious.


>From 92e824e2cfa02ecfc41b78e91acdd5ac0a845c17 Mon Sep 17 00:00:00 2001
From: John Denker <[email protected]>
Date: Sat, 4 Apr 2015 16:36:51 -0700
Subject: [PATCH] fix CPU-hogging loop; don't try to read when EoF already seen

---
 apps/s_client.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/apps/s_client.c b/apps/s_client.c
index ec11617..775420a 100644
--- a/apps/s_client.c
+++ b/apps/s_client.c
@@ -729,6 +729,7 @@ int MAIN(int argc, char **argv)
     int crl_download = 0;
     STACK_OF(X509_CRL) *crls = NULL;
     int sdebug = 0;
+    int tty_at_EoF = 0;
 
     meth = SSLv23_client_method();
 
@@ -1719,7 +1720,12 @@ int MAIN(int argc, char **argv)
         if (!ssl_pending) {
 #if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)
             if (tty_on) {
-                if (read_tty)
+/* Note that select() returns whenever a read _would not block_ */
+/* and being at EoF satisfies this criterion ...                */
+/* even though a read after EoF is not interesting to us        */
+/* and would cause a CPU-hogging loop.                          */
+/* Hence the factor of tty_at_EoF here.                         */
+                if (read_tty && !tty_at_EoF)
                     openssl_fdset(fileno(stdin), &readfds);
                 if (write_tty)
                     openssl_fdset(fileno(stdout), &writefds);
@@ -1977,6 +1983,8 @@ int MAIN(int argc, char **argv)
             } else
                 i = raw_read_stdin(cbuf, BUFSIZZ);
 
+            if (i == 0) tty_at_EoF = 1;
+
             if ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == 'Q'))) {
                 BIO_printf(bio_err, "DONE\n");
                 ret = 0;
-- 
2.1.0

_______________________________________________
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev

Reply via email to