diff options
author | Thays Grazia <thaystg@gmail.com> | 2020-01-26 06:00:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-26 06:00:41 +0300 |
commit | f8c34dc56b7849bd6fe2cd2051b9522a7b03413f (patch) | |
tree | 0dc61804f49ac697c02c62011ee33706009bb7b8 /mcs/class | |
parent | 4704c85c9db3fb1dccd9191bec4b349180a193ee (diff) |
[debugger] Access invalid memory address using PointerValue Command. (#18537)
* Validate the address that came from IDE using PointerValue. The IDE can send an invalid address and it was crashing mono.
Fixes #18191
Fixes #15612
Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
Diffstat (limited to 'mcs/class')
-rw-r--r-- | mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PointerValue.cs | 13 | ||||
-rw-r--r-- | mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs | 15 | ||||
-rw-r--r-- | mcs/class/Mono.Debugger.Soft/Test/dtest.cs | 26 |
3 files changed, 52 insertions, 2 deletions
diff --git a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PointerValue.cs b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PointerValue.cs index 2cf9dfa418b..d407b417b51 100644 --- a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PointerValue.cs +++ b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/PointerValue.cs @@ -51,10 +51,19 @@ namespace Mono.Debugger.Soft // Since protocol version 2.46 public Value Value { get { + ValueImpl value; if (Address == 0) return null; - - return vm.DecodeValue (vm.conn.Pointer_GetValue (Address, Type)); + try { + value = vm.conn.Pointer_GetValue (Address, Type); + } + catch (CommandException ex) { + if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT) + throw new ArgumentException ("Invalid pointer address."); + else + throw; + } + return vm.DecodeValue (value); } } diff --git a/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs b/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs index 945ea48c38b..1bbb04d4709 100644 --- a/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs +++ b/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs @@ -609,6 +609,10 @@ public class Tests : TestsBase, ITest2 fixed_size_array(); test_new_exception_filter(); test_async_debug_generics(); + if (args.Length >0 && args [0] == "pointer_arguments2") { + pointers2 (); + return 0; + } return 3; } @@ -2232,6 +2236,17 @@ public class Tests : TestsBase, ITest2 rtMethod.Invoke(rtObject, new object[] { }); } + public static unsafe void pointer_arguments2 (int* a) { + *a = 0; + } + + [MethodImplAttribute (MethodImplOptions.NoInlining)] + public static unsafe void pointers2 () { + int[] a = new [] {1,2,3}; + fixed (int* pa = a) + pointer_arguments2 (pa); + } + [MethodImplAttribute (MethodImplOptions.NoInlining)] public static void new_thread_hybrid_exception() { try diff --git a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs index 05d112e3f88..7be3ae3e6eb 100644 --- a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs +++ b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs @@ -5174,6 +5174,32 @@ public class DebuggerTests e = step_in_await ("MoveNext", e); e = step_in_await ("MoveNext", e); } + + [Test] + public void InvalidPointer_GetValue () { + vm.Detach (); + Start (dtest_app_path, "pointer_arguments2"); + Event e = run_until ("pointer_arguments2"); + var frame = e.Thread.GetFrames () [0]; + + var param = frame.Method.GetParameters()[0]; + Assert.AreEqual("Int32*", param.ParameterType.Name); + + var pointerValue = frame.GetValue(param) as PointerValue; + Assert.AreEqual("Int32*", pointerValue.Type.Name); + + + var pointerValue2 = new PointerValue (pointerValue.VirtualMachine, pointerValue.Type, 200); + + try { + var val = pointerValue2.Value; + } + catch (ArgumentException ex) { + Assert.IsInstanceOfType (typeof (ArgumentException), ex); + } + } + + #endif } // class DebuggerTests |