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

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 8a4c7484fa Avoid possible lost update
8a4c7484fa is described below

commit 8a4c7484fa37008bc0bbf188010e000dfb7600a6
Author: remm <r...@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 7d5df2e007..d8f2afec7e 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;
@@ -142,6 +143,7 @@ public class SecureNio2Channel extends Nio2Channel  {
         sslEngine = null;
         sniComplete = false;
         handshakeComplete = false;
+        handshakeWrapQueueLength.set(0);
         unwrapBeforeRead = true;
         closed = false;
         closing = false;
@@ -771,7 +773,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")));
                         }
@@ -906,7 +908,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) {
@@ -973,7 +975,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")));
                                     }
@@ -1091,7 +1093,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")));
                                     }
@@ -1205,7 +1207,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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to