src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java
changeset 53289 5022a4915fe9
parent 53064 103ed9569fc8
child 54443 dfba4e321ab3
--- a/src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java	Fri Jan 11 10:03:00 2019 +0100
+++ b/src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java	Mon Jan 14 10:00:45 2019 -0800
@@ -247,6 +247,19 @@
             hsStatus = ciphertext.handshakeStatus;
         } else {
             hsStatus = getHandshakeStatus();
+            if (ciphertext == null && !conContext.isNegotiated &&
+                    conContext.isInboundClosed() &&
+                    hsStatus == HandshakeStatus.NEED_WRAP) {
+                // Even the outboud is open, no futher data could be wrapped as:
+                //     1. the outbound is empty
+                //     2. no negotiated connection
+                //     3. the inbound has closed, cannot complete the handshake
+                //
+                // Mark the engine as closed if the handshake status is
+                // NEED_WRAP. Otherwise, it could lead to dead loops in
+                // applications.
+                status = Status.CLOSED;
+            }
         }
 
         int deltaSrcs = srcsRemains;
@@ -279,7 +292,7 @@
         }
 
         if (ciphertext == null) {
-            return Ciphertext.CIPHERTEXT_NULL;
+            return null;
         }
 
         // Is the handshake completed?