From d538e5710e7aedea9ce1319bb8cdcfe18f8609a0 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 21 Oct 2024 22:35:17 +0000 Subject: [PATCH 1/2] Initialize managed and native values to null when the other is null. --- src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs index 6d9c3d7680f31..235bee883d13d 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs @@ -802,6 +802,7 @@ internal static unsafe void ConvertContentsToNative(ICustomMarshaler marshaler, // COMPAT: We never pass null to MarshalManagedToNative. if (pManagedHome is null) { + *pNativeHome = IntPtr.Zero; return; } @@ -813,6 +814,7 @@ internal static void ConvertContentsToManaged(ICustomMarshaler marshaler, ref ob // COMPAT: We never pass null to MarshalNativeToManaged. if (*pNativeHome == IntPtr.Zero) { + pManagedHome = null; return; } From 877e4a1393824fa6842c75c9836b924cddda8e61 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 21 Oct 2024 16:12:20 -0700 Subject: [PATCH 2/2] Update StubHelpers.cs --- src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs index 235bee883d13d..3c9c08b7c0e81 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs @@ -809,7 +809,7 @@ internal static unsafe void ConvertContentsToNative(ICustomMarshaler marshaler, *pNativeHome = marshaler.MarshalManagedToNative(pManagedHome); } - internal static void ConvertContentsToManaged(ICustomMarshaler marshaler, ref object pManagedHome, IntPtr* pNativeHome) + internal static void ConvertContentsToManaged(ICustomMarshaler marshaler, ref object? pManagedHome, IntPtr* pNativeHome) { // COMPAT: We never pass null to MarshalNativeToManaged. if (*pNativeHome == IntPtr.Zero)