This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 3a152beabd Follow up to "Improve handshake robustness"
3a152beabd is described below
commit 3a152beabdac64bb242d2c838c2782ea1131d15c
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 961b92a0b4..15cf54c989 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]