You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2024/09/06 08:37:03 UTC
(tomcat) branch 10.1.x updated: Avoid possible lost update
This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new de70d136d3 Avoid possible lost update
de70d136d3 is described below
commit de70d136d3fd3c63f4cb7d59e86e911bc4881683
Author: remm <re...@apache.org>
AuthorDate: Fri Sep 6 10:29:40 2024 +0200
Avoid possible lost update
Found by Coverity.
---
java/org/apache/tomcat/util/net/SecureNio2Channel.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/java/org/apache/tomcat/util/net/SecureNio2Channel.java b/java/org/apache/tomcat/util/net/SecureNio2Channel.java
index c2167f6683..20abc1b6f4 100644
--- a/java/org/apache/tomcat/util/net/SecureNio2Channel.java
+++ b/java/org/apache/tomcat/util/net/SecureNio2Channel.java
@@ -30,6 +30,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
@@ -69,7 +70,7 @@ public class SecureNio2Channel extends Nio2Channel {
protected volatile boolean sniComplete = false;
private volatile boolean handshakeComplete = false;
- private volatile int handshakeWrapQueueLength = 0;
+ private final AtomicInteger handshakeWrapQueueLength = new AtomicInteger();
private volatile HandshakeStatus handshakeStatus; //gets set by handshake
protected boolean closed;
@@ -137,6 +138,7 @@ public class SecureNio2Channel extends Nio2Channel {
sslEngine = null;
sniComplete = false;
handshakeComplete = false;
+ handshakeWrapQueueLength.set(0);
unwrapBeforeRead = true;
closed = false;
closing = false;
@@ -766,7 +768,7 @@ public class SecureNio2Channel extends Nio2Channel {
if (unwrap.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
tasks();
} else if (unwrap.getHandshakeStatus() == HandshakeStatus.NEED_WRAP) {
- if (++handshakeWrapQueueLength > HANDSHAKE_WRAP_QUEUE_LENGTH_LIMIT) {
+ if (handshakeWrapQueueLength.incrementAndGet() > HANDSHAKE_WRAP_QUEUE_LENGTH_LIMIT) {
throw new ExecutionException(
new IOException(sm.getString("channel.nio.ssl.handshakeWrapQueueTooLong")));
}
@@ -901,7 +903,7 @@ public class SecureNio2Channel extends Nio2Channel {
netOutBuffer.clear();
SSLEngineResult result = sslEngine.wrap(src, netOutBuffer);
// Call to wrap() will have included any required handshake data
- handshakeWrapQueueLength = 0;
+ handshakeWrapQueueLength.set(0);
written = result.bytesConsumed();
netOutBuffer.flip();
if (result.getStatus() == Status.OK) {
@@ -968,7 +970,7 @@ public class SecureNio2Channel extends Nio2Channel {
if (unwrap.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
tasks();
} else if (unwrap.getHandshakeStatus() == HandshakeStatus.NEED_WRAP) {
- if (++handshakeWrapQueueLength > HANDSHAKE_WRAP_QUEUE_LENGTH_LIMIT) {
+ if (handshakeWrapQueueLength.incrementAndGet() > HANDSHAKE_WRAP_QUEUE_LENGTH_LIMIT) {
throw new ExecutionException(new IOException(
sm.getString("channel.nio.ssl.handshakeWrapQueueTooLong")));
}
@@ -1086,7 +1088,7 @@ public class SecureNio2Channel extends Nio2Channel {
if (unwrap.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
tasks();
} else if (unwrap.getHandshakeStatus() == HandshakeStatus.NEED_WRAP) {
- if (++handshakeWrapQueueLength > HANDSHAKE_WRAP_QUEUE_LENGTH_LIMIT) {
+ if (handshakeWrapQueueLength.incrementAndGet() > HANDSHAKE_WRAP_QUEUE_LENGTH_LIMIT) {
throw new ExecutionException(new IOException(
sm.getString("channel.nio.ssl.handshakeWrapQueueTooLong")));
}
@@ -1200,7 +1202,7 @@ public class SecureNio2Channel extends Nio2Channel {
// Wrap the source data into the internal buffer
SSLEngineResult result = sslEngine.wrap(src, netOutBuffer);
// Call to wrap() will have included any required handshake data
- handshakeWrapQueueLength = 0;
+ handshakeWrapQueueLength.set(0);
final int written = result.bytesConsumed();
netOutBuffer.flip();
if (result.getStatus() == Status.OK) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org