Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Robinson <arobins@microsoft.com>2022-06-18 07:31:25 +0300
committerGitHub <noreply@github.com>2022-06-18 07:31:25 +0300
commit4adb1172658f74e6a513bece426005d7f2ba7a04 (patch)
tree919ed5ce0a595eda71aab7c99150643e44934992 /src/tests/baseservices
parente9175f473f97c2632c3e810f4b0811b04ed47cb7 (diff)
Harden for null byrefs (#70317)
* Remove enum_flag_Unrestored usage in boxing stubs. * Add AND instruction (21h) to x86 decoder. * Update mono for null ref in interpreter paths. * Disable test on llvmfullaot and wasm * Handle null destination for intrinsics.
Diffstat (limited to 'src/tests/baseservices')
-rw-r--r--src/tests/baseservices/invalid_operations/InvalidOperations.csproj12
-rw-r--r--src/tests/baseservices/invalid_operations/ManagedPointers.cs84
2 files changed, 96 insertions, 0 deletions
diff --git a/src/tests/baseservices/invalid_operations/InvalidOperations.csproj b/src/tests/baseservices/invalid_operations/InvalidOperations.csproj
new file mode 100644
index 00000000000..3c04f092ae8
--- /dev/null
+++ b/src/tests/baseservices/invalid_operations/InvalidOperations.csproj
@@ -0,0 +1,12 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="ManagedPointers.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/src/tests/baseservices/invalid_operations/ManagedPointers.cs b/src/tests/baseservices/invalid_operations/ManagedPointers.cs
new file mode 100644
index 00000000000..c5357cf0354
--- /dev/null
+++ b/src/tests/baseservices/invalid_operations/ManagedPointers.cs
@@ -0,0 +1,84 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Threading;
+
+using Xunit;
+
+public unsafe class ManagedPointers
+{
+ [Fact]
+ public static void Validate_BoxingHelpers_NullByRef()
+ {
+ Console.WriteLine($"Running {nameof(Validate_BoxingHelpers_NullByRef)}...");
+ Assert.Throws<NullReferenceException>(() =>
+ {
+ object boxed = Unsafe.NullRef<int>();
+ });
+ Assert.Throws<NullReferenceException>(() =>
+ {
+ object boxed = Unsafe.NullRef<Guid>();
+ });
+ Assert.Throws<NullReferenceException>(() =>
+ {
+ object boxed = Unsafe.NullRef<string>();
+ });
+ }
+
+ [Fact]
+ public static void Validate_GeneratedILStubs_NullByRef()
+ {
+ Console.WriteLine($"Running {nameof(Validate_GeneratedILStubs_NullByRef)}...");
+ {
+ var fptr = (delegate*unmanaged<ref int, nint>)(delegate*unmanaged<void*, nint>)&PassByRef;
+ Assert.Equal(0, fptr(ref Unsafe.NullRef<int>()));
+ }
+
+ {
+ var fptr = (delegate*unmanaged<ref Guid, nint>)(delegate*unmanaged<void*, nint>)&PassByRef;
+ Assert.Equal(0, fptr(ref Unsafe.NullRef<Guid>()));
+ }
+
+ Assert.Throws<NullReferenceException>(() =>
+ {
+ var fptr = (delegate*unmanaged<ref string, nint>)(delegate*unmanaged<void*, nint>)&PassByRef;
+ fptr(ref Unsafe.NullRef<string>());
+ });
+
+ [UnmanagedCallersOnly]
+ static nint PassByRef(void* a) => (nint)a;
+ }
+
+ [Fact]
+ public static void Validate_IntrinsicMethodsWithByRef_NullByRef()
+ {
+ Console.WriteLine($"Running {nameof(Validate_IntrinsicMethodsWithByRef_NullByRef)}...");
+
+ Assert.Throws<NullReferenceException>(() => Interlocked.Increment(ref Unsafe.NullRef<int>()));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Increment(ref Unsafe.NullRef<long>()));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Decrement(ref Unsafe.NullRef<int>()));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Decrement(ref Unsafe.NullRef<long>()));
+
+ Assert.Throws<NullReferenceException>(() => Interlocked.And(ref Unsafe.NullRef<int>(), 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.And(ref Unsafe.NullRef<long>(), 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Or(ref Unsafe.NullRef<int>(), 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Or(ref Unsafe.NullRef<long>(), 0));
+
+ Assert.Throws<NullReferenceException>(() => Interlocked.Exchange(ref Unsafe.NullRef<int>(), 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Exchange(ref Unsafe.NullRef<long>(), 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Exchange(ref Unsafe.NullRef<float>(), 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Exchange(ref Unsafe.NullRef<double>(), 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Exchange(ref Unsafe.NullRef<object>(), new object()));
+ Assert.Throws<NullReferenceException>(() => Interlocked.Exchange<object>(ref Unsafe.NullRef<object>(), new object()));
+
+ Assert.Throws<NullReferenceException>(() => Interlocked.CompareExchange(ref Unsafe.NullRef<int>(), 0, 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.CompareExchange(ref Unsafe.NullRef<long>(), 0, 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.CompareExchange(ref Unsafe.NullRef<float>(), 0, 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.CompareExchange(ref Unsafe.NullRef<double>(), 0, 0));
+ Assert.Throws<NullReferenceException>(() => Interlocked.CompareExchange(ref Unsafe.NullRef<object>(), new object(), new object()));
+ Assert.Throws<NullReferenceException>(() => Interlocked.CompareExchange<object>(ref Unsafe.NullRef<object>(), new object(), new object()));
+ }
+} \ No newline at end of file