Remove invalid assert in EvpPKeyDuplicate
authorKevin Jones <kevin@vcsjones.com>
Fri, 19 May 2023 17:25:05 +0000 (13:25 -0400)
committerGitHub <noreply@github.com>
Fri, 19 May 2023 17:25:05 +0000 (13:25 -0400)
EvpPKeyDuplicate has an invalid assert in it where it asserts that the handle it was passed is not IsInvalid. This may not be true in a multi-threaded scenario where an object is disposed by one thread while another thread is trying to use the resource.

Since we are marshaling the handle as a SafeHandle, just let it do the right thing of throwing an ObjectDisposedException when the marshaller attempts to add a reference to the handle.

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

index bbb7a67bd2df8ef3239fdd1545dd99aa58c50cba..f61791bfdae12cda1802a048fb471bd0ae787afb 100644 (file)
@@ -22,8 +22,6 @@ internal static partial class Interop
             SafeEvpPKeyHandle currentKey,
             EvpAlgorithmId algorithmId)
         {
-            Debug.Assert(!currentKey.IsInvalid);
-
             SafeEvpPKeyHandle pkey = CryptoNative_EvpPKeyDuplicate(
                 currentKey,
                 algorithmId);