Comment reformatted to comply with new OpenSSL coding style chapter 8
  https://www.openssl.org/about/codingstyle.txt

Functionality unchanged from previous patch.



>From 9e896a7a0f1ae28ab32c025ae2a5730aa7343c6a 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 | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/apps/s_client.c b/apps/s_client.c
index ec11617..0d41318 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,14 @@ 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 +1985,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