From fc65281072f9259f0b03a291b9c549bc9d792752 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 19 Dec 2022 11:10:20 +0000 Subject: [PATCH] Use Unsafe.NullRef (#79589) --- .../Interop.EVP.Cipher.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs index f47bf5d3e1b51..df82c65487de1 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; @@ -115,8 +116,12 @@ ref MemoryMarshal.GetReference(input), internal static void EvpCipherSetInputLength(SafeEvpCipherCtxHandle ctx, int inputLength) { - ref byte nullRef = ref MemoryMarshal.GetReference(Span.Empty); - if (!EvpCipherUpdate(ctx, ref nullRef, out _, ref nullRef, inputLength)) + if (!EvpCipherUpdate( + ctx, + ref Unsafe.NullRef(), + out _, + ref Unsafe.NullRef(), + inputLength)) { throw CreateOpenSslCryptographicException(); } @@ -229,8 +234,7 @@ internal static void EvpCipherSetCcmTag(SafeEvpCipherCtxHandle ctx, ReadOnlySpan internal static void EvpCipherSetCcmTagLength(SafeEvpCipherCtxHandle ctx, int tagLength) { - ref byte nullRef = ref MemoryMarshal.GetReference(Span.Empty); - if (!EvpCipherSetCcmTag(ctx, ref nullRef, tagLength)) + if (!EvpCipherSetCcmTag(ctx, ref Unsafe.NullRef(), tagLength)) { throw CreateOpenSslCryptographicException(); }