handle_established_connection(): Skip the poll()/select() calls
authorFabian Keil <fk@fabiankeil.de>
Wed, 10 Mar 2021 16:50:53 +0000 (17:50 +0100)
committerFabian Keil <fk@fabiankeil.de>
Fri, 12 Mar 2021 11:34:11 +0000 (12:34 +0100)
... if TLS data is pending on the server socket.

The TLS library may have already consumed all the data from the server
response in which case poll() and select() will not detect that data is
available to be read.

Fixes SF bug #926 reported by Wen Yue.

jcc.c

diff --git a/jcc.c b/jcc.c
index 648fd45..d8840b6 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -3085,6 +3085,18 @@ static void handle_established_connection(struct client_state *csp)
 
    for (;;)
    {
+#ifdef FEATURE_HTTPS_INSPECTION
+      if (server_use_ssl(csp) && is_ssl_pending(&(csp->ssl_server_attr)))
+      {
+         /*
+          * It's possible that the TLS library already consumed all the
+          * data the server intends to send. If that happens poll() and
+          * select() will no longer see the data as available so we have
+          * to skip the calls.
+          */
+         goto server_wants_to_talk;
+      }
+#endif
 #ifndef HAVE_POLL
       FD_ZERO(&rfds);
 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
@@ -3358,6 +3370,9 @@ static void handle_established_connection(struct client_state *csp)
       if (FD_ISSET(csp->server_connection.sfd, &rfds))
 #endif /* HAVE_POLL */
       {
+#ifdef FEATURE_HTTPS_INSPECTION
+         server_wants_to_talk:
+#endif
 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
          /*
           * If we are buffering content, we don't want to eat up to