From 294b2ba02b667548617a94cd99592110ac230add Mon Sep 17 00:00:00 2001
From: Simone Bordet <simone.bordet@gmail.com>
Date: Mon, 22 Mar 2021 10:39:36 +0100
Subject: [PATCH] Fixes #6072 - jetty server high CPU when client send data
 length > 17408.

Updates after review.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
---
 .../main/java/org/eclipse/jetty/io/ssl/SslConnection.java  | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java
index b2482e7..44c7f10 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java
@@ -602,14 +602,15 @@ public class SslConnection extends AbstractConnection implements Connection.Upgr
                                     return filled = -1;
 
                                 case BUFFER_UNDERFLOW:
-                                    if (net_filled > 0)
+                                    if (BufferUtil.space(_encryptedInput) == 0)
                                     {
-                                        if (BufferUtil.space(_encryptedInput) > 0)
-                                            continue; // try filling some more
                                         BufferUtil.clear(_encryptedInput);
                                         throw new SSLHandshakeException("Encrypted buffer max length exceeded");
                                     }
 
+                                    if (net_filled > 0)
+                                        continue; // try filling some more
+
                                     _underflown = true;
                                     if (net_filled < 0 && _sslEngine.getUseClientMode())
                                     {
-- 
2.23.0

