From 4a5b84605414521d45f100986253682efde1604d Mon Sep 17 00:00:00 2001 From: kenlon <366899789@qq.com> Date: Thu, 1 Sep 2022 00:23:17 +0800 Subject: [PATCH] Fix infinite loop during TLS handshake(Only .NET6) (#583) Fix infinite loop caused by disconnection during TLS handshake, and the memory exploded instantly. --- src/DotNetty.Handlers/Tls/TlsHandler.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/DotNetty.Handlers/Tls/TlsHandler.cs b/src/DotNetty.Handlers/Tls/TlsHandler.cs index 8e4749f..082fa0c 100644 --- a/src/DotNetty.Handlers/Tls/TlsHandler.cs +++ b/src/DotNetty.Handlers/Tls/TlsHandler.cs @@ -506,6 +506,13 @@ namespace DotNetty.Handlers.Tls } int read = currentReadFuture.Result; + + if (read == 0) + { + //Stream closed + return; + } + AddBufferToOutput(outputBuffer, read, output); } @@ -763,4 +770,4 @@ namespace DotNetty.Handlers.Tls public static bool HasAny(this TlsHandlerState value, TlsHandlerState testValue) => (value & testValue) != 0; } -} \ No newline at end of file +}