Skip to content

Commit

Permalink
[release/7.0-rc1] hold reference to SslContextHandle to prevent crash…
Browse files Browse the repository at this point in the history
…es (#74367)

* 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: wfurt <tweinfurt@yahoo.com>
Co-authored-by: Dan Moseley <danmose@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
  • Loading branch information
4 people committed Aug 23, 2022
1 parent 12cc3d4 commit 7193b90
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 7193b90

Please sign in to comment.