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

johnnyv pushed a commit to branch bugfix/DIRMINA1132
in repository https://gitbox.apache.org/repos/asf/mina.git


The following commit(s) were added to refs/heads/bugfix/DIRMINA1132 by this 
push:
     new c1f9e25  Adds hard ceiling for the number of queued cleartext messages 
in SSL2Handler
c1f9e25 is described below

commit c1f9e2555735d0bbdd6506826765610380382d77
Author: Jonathan Valliere <john...@apache.org>
AuthorDate: Sat Jul 31 04:17:00 2021 -0400

    Adds hard ceiling for the number of queued cleartext messages in
    SSL2Handler
---
 .../org/apache/mina/filter/ssl2/SSL2Handler.java   | 28 +++++++++++-----------
 .../org/apache/mina/filter/ssl2/SSL2HandlerG0.java | 12 ++++++++++
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git 
a/mina-core/src/main/java/org/apache/mina/filter/ssl2/SSL2Handler.java 
b/mina-core/src/main/java/org/apache/mina/filter/ssl2/SSL2Handler.java
index cdf186e..9f6114b 100644
--- a/mina-core/src/main/java/org/apache/mina/filter/ssl2/SSL2Handler.java
+++ b/mina-core/src/main/java/org/apache/mina/filter/ssl2/SSL2Handler.java
@@ -20,12 +20,12 @@ public abstract class SSL2Handler {
        /**
         * Minimum size of encoder buffer in packets
         */
-       static protected final int MIN_ENCODER_PACKETS = 2;
+       static protected final int MIN_ENCODER_BUFFER_PACKETS = 2;
 
        /**
         * Maximum size of encoder buffer in packets
         */
-       static protected final int MAX_ENCODER_PACKETS = 8;
+       static protected final int MAX_ENCODER_BUFFER_PACKETS = 8;
 
        /**
         * Zero length buffer used to prime the ssl engine
@@ -65,7 +65,7 @@ public abstract class SSL2Handler {
        /**
         * Progressive decoder buffer
         */
-       protected IoBuffer mReceiveBuffer;
+       protected IoBuffer mDecodeBuffer;
 
        /**
         * Instantiates a new handler
@@ -185,19 +185,19 @@ public abstract class SSL2Handler {
         * @return buffer to decode
         */
        protected IoBuffer resume_decode_buffer(IoBuffer source) {
-               if (mReceiveBuffer == null)
+               if (mDecodeBuffer == null)
                        if (source == null)
                                return IoBuffer.allocate(0);
                        else
                                return source;
                else {
                        if (source != null) {
-                               mReceiveBuffer.expand(source.remaining());
-                               mReceiveBuffer.put(source);
+                               mDecodeBuffer.expand(source.remaining());
+                               mDecodeBuffer.put(source);
                                source.free();
                        }
-                       mReceiveBuffer.flip();
-                       return mReceiveBuffer;
+                       mDecodeBuffer.flip();
+                       return mDecodeBuffer;
                }
        }
 
@@ -210,15 +210,15 @@ public abstract class SSL2Handler {
        protected void save_decode_buffer(IoBuffer source) {
                if (source.hasRemaining()) {
                        if (source.isDerived()) {
-                               this.mReceiveBuffer = 
IoBuffer.allocate(source.remaining());
-                               this.mReceiveBuffer.put(source);
+                               this.mDecodeBuffer = 
IoBuffer.allocate(source.remaining());
+                               this.mDecodeBuffer.put(source);
                        } else {
                                source.compact();
-                               this.mReceiveBuffer = source;
+                               this.mDecodeBuffer = source;
                        }
                } else {
                        source.free();
-                       this.mReceiveBuffer = null;
+                       this.mDecodeBuffer = null;
                }
        }
 
@@ -232,8 +232,8 @@ public abstract class SSL2Handler {
                SSLSession session = this.mEngine.getHandshakeSession();
                if (session == null)
                        session = this.mEngine.getSession();
-               int packets = Math.max(MIN_ENCODER_PACKETS,
-                               Math.min(MAX_ENCODER_PACKETS, 1 + (estimate / 
session.getApplicationBufferSize())));
+               int packets = Math.max(MIN_ENCODER_BUFFER_PACKETS,
+                               Math.min(MAX_ENCODER_BUFFER_PACKETS, 1 + 
(estimate / session.getApplicationBufferSize())));
                return IoBuffer.allocate(packets * 
session.getPacketBufferSize());
        }
 
diff --git 
a/mina-core/src/main/java/org/apache/mina/filter/ssl2/SSL2HandlerG0.java 
b/mina-core/src/main/java/org/apache/mina/filter/ssl2/SSL2HandlerG0.java
index 588ab68..168ad8f 100644
--- a/mina-core/src/main/java/org/apache/mina/filter/ssl2/SSL2HandlerG0.java
+++ b/mina-core/src/main/java/org/apache/mina/filter/ssl2/SSL2HandlerG0.java
@@ -1,5 +1,6 @@
 package org.apache.mina.filter.ssl2;
 
+import java.nio.BufferOverflowException;
 import java.util.concurrent.Executor;
 
 import javax.net.ssl.SSLEngine;
@@ -15,6 +16,11 @@ import org.apache.mina.filter.ssl.SslEvent;
 public class SSL2HandlerG0 extends SSL2Handler {
 
        /**
+        * Maximum number of queued messages waiting for encoding
+        */
+       static protected final int MAX_QUEUED_MESSAGES = 64;
+
+       /**
         * Maximum number of messages waiting acknowledgement
         */
        static protected final int MAX_UNACK_MESSAGES = 6;
@@ -203,12 +209,18 @@ public class SSL2HandlerG0 extends SSL2Handler {
                                        LOGGER.debug("{} write() - unable to 
write right now, saving request for later", toString(),
                                                        request);
                                }
+                               if (this.mEncodeQueue.size() == 
MAX_QUEUED_MESSAGES) {
+                                       throw new BufferOverflowException();
+                               }
                                this.mEncodeQueue.add(request);
                        }
                } else {
                        if (LOGGER.isDebugEnabled()) {
                                LOGGER.debug("{} write() - unable to write 
right now, saving request for later", toString(), request);
                        }
+                       if (this.mEncodeQueue.size() == MAX_QUEUED_MESSAGES) {
+                               throw new BufferOverflowException();
+                       }
                        this.mEncodeQueue.add(request);
                }
        }

Reply via email to