Skip to content

Commit 2235858

Browse files
wfurtdanmoseleystephentoub
authored
hold reference to SslContextHandle to prevent crashes (#73972)
* fold reference to SslContextHandle to prevent crashes * Update src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Dan Moseley <danmose@microsoft.com> Co-authored-by: Stephen Toub <stoub@microsoft.com>
1 parent e461b77 commit 2235858

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ internal static SafeSslHandle AllocateSslHandle(SslAuthenticationOptions sslAuth
394394
if (cacheSslContext && !string.IsNullOrEmpty(punyCode))
395395
{
396396
sslCtxHandle.TrySetSession(sslHandle, punyCode);
397+
bool ignored = false;
398+
sslCtxHandle.DangerousAddRef(ref ignored);
399+
sslHandle.SslContextHandle = sslCtxHandle;
397400
}
398401

399402
// relevant to TLS 1.3 only: if user supplied a client cert or cert callback,

src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ internal sealed class SafeSslHandle : SafeDeleteSslContext
335335
private bool _handshakeCompleted;
336336

337337
public GCHandle AlpnHandle;
338+
public SafeSslContextHandle? SslContextHandle;
338339

339340
public bool IsServer
340341
{
@@ -432,6 +433,8 @@ protected override bool ReleaseHandle()
432433
Disconnect();
433434
}
434435

436+
SslContextHandle?.DangerousRelease();
437+
435438
IntPtr h = handle;
436439
SetHandle(IntPtr.Zero);
437440
Interop.Ssl.SslDestroy(h); // will free the handles underlying _readBio and _writeBio

0 commit comments

Comments
 (0)