This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 38e57e71e5 Follow up to "Improve handshake robustness"
38e57e71e5 is described below

commit 38e57e71e589a7b7b077526a26ec7bf7f312893d
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Sep 2 10:37:21 2026 +0100

    Follow up to "Improve handshake robustness"
    
    Write never returns -1 and can't return 0 in this case
    Reduce code duplication
---
 .../tomcat/websocket/AsyncChannelWrapperSecure.java | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java 
b/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
index ca25622714..872f30f189 100644
--- a/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
+++ b/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
@@ -265,10 +265,7 @@ public class AsyncChannelWrapperSecure implements 
AsyncChannelWrapper {
                     if (forceRead) {
                         forceRead = false;
                         Future<Integer> f = 
socketChannel.read(socketReadBuffer);
-                        Integer socketRead = f.get();
-                        if (socketRead.intValue() == -1) {
-                            throw new 
EOFException(sm.getString("asyncChannelWrapperSecure.eof"));
-                        }
+                        checkFutureRead(f);
                     }
 
                     socketReadBuffer.flip();
@@ -339,6 +336,14 @@ public class AsyncChannelWrapperSecure implements 
AsyncChannelWrapper {
     }
 
 
+    private static void checkFutureRead(Future<Integer> future) throws 
EOFException, ExecutionException,
+            InterruptedException {
+        Integer bytesRead = future.get();
+        if (bytesRead.intValue() < 0) {
+            throw new 
EOFException(sm.getString("asyncChannelWrapperSecure.eof"));
+        }
+    }
+
     private class WebSocketSslHandshakeThread extends Thread {
 
         private final WrapperFuture<Void,Void> hFuture;
@@ -371,9 +376,7 @@ public class AsyncChannelWrapperSecure implements 
AsyncChannelWrapper {
                             socketWriteBuffer.flip();
                             while (socketWriteBuffer.hasRemaining()) {
                                 Future<Integer> fWrite = 
socketChannel.write(socketWriteBuffer);
-                                if (fWrite.get() < 0) {
-                                    throw new 
EOFException(sm.getString("asyncChannelWrapperSecure.eof"));
-                                }
+                                fWrite.get();
                             }
                             break;
                         }
@@ -381,9 +384,7 @@ public class AsyncChannelWrapperSecure implements 
AsyncChannelWrapper {
                             socketReadBuffer.compact();
                             if (socketReadBuffer.position() == 0 || 
resultStatus == Status.BUFFER_UNDERFLOW) {
                                 Future<Integer> fRead = 
socketChannel.read(socketReadBuffer);
-                                if (fRead.get() < 0) {
-                                    throw new 
EOFException(sm.getString("asyncChannelWrapperSecure.eof"));
-                                }
+                                checkFutureRead(fRead);
                             }
                             socketReadBuffer.flip();
                             SSLEngineResult r = 
sslEngine.unwrap(socketReadBuffer, DUMMY);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to