Skip to content

Commit

Permalink
hold reference to SslContextHandle to prevent crashes (#73972)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Dan Moseley <[email protected]>
Co-authored-by: Stephen Toub <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2022
1 parent e461b77 commit 2235858
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ internal static SafeSslHandle AllocateSslHandle(SslAuthenticationOptions sslAuth
if (cacheSslContext && !string.IsNullOrEmpty(punyCode))
{
sslCtxHandle.TrySetSession(sslHandle, punyCode);
bool ignored = false;
sslCtxHandle.DangerousAddRef(ref ignored);
sslHandle.SslContextHandle = sslCtxHandle;
}

// relevant to TLS 1.3 only: if user supplied a client cert or cert callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ internal sealed class SafeSslHandle : SafeDeleteSslContext
private bool _handshakeCompleted;

public GCHandle AlpnHandle;
public SafeSslContextHandle? SslContextHandle;

public bool IsServer
{
Expand Down Expand Up @@ -432,6 +433,8 @@ protected override bool ReleaseHandle()
Disconnect();
}

SslContextHandle?.DangerousRelease();

IntPtr h = handle;
SetHandle(IntPtr.Zero);
Interop.Ssl.SslDestroy(h); // will free the handles underlying _readBio and _writeBio
Expand Down

0 comments on commit 2235858

Please sign in to comment.