From fb25b76d3b4873153964558aec267a8b0c0ae31c Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Mon, 6 Feb 2023 11:32:59 -0800 Subject: [PATCH] prevent use of null when processing alpn list (#81629) --- .../Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs | 5 +++++ .../Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs index 1bfaff2..e485326 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs @@ -683,6 +683,11 @@ internal static partial class Interop *outlen = 0; IntPtr sslData = Ssl.SslGetData(ssl); + if (sslData == IntPtr.Zero) + { + return Ssl.SSL_TLSEXT_ERR_ALERT_FATAL; + } + // reset application data to avoid dangling pointer. Ssl.SslSetData(ssl, IntPtr.Zero); diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs index 986754d..d5788bb 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs @@ -421,6 +421,7 @@ namespace Microsoft.Win32.SafeHandles if (AlpnHandle.IsAllocated) { + Interop.Ssl.SslSetData(handle, IntPtr.Zero); AlpnHandle.Free(); } -- 2.7.4