diff options
author | Zoltan Varga <vargaz@gmail.com> | 2018-11-08 21:41:47 +0300 |
---|---|---|
committer | Ludovic Henry <luhenry@microsoft.com> | 2018-11-08 21:41:47 +0300 |
commit | af0191cde02c31ce827f94ab5213513e608dca05 (patch) | |
tree | d0ff809ae74fbc9de1e10c2d14ab48b2c2ad074e | |
parent | a8a7a3401a584390f94e8a17c478c00a26e5ccc3 (diff) |
[interp] Add a null check to MINT_LDELEMA. (#11606)
Fixes https://github.com/mono/mono/issues/11603.
-rw-r--r-- | mono/mini/arrays.cs | 14 | ||||
-rw-r--r-- | mono/mini/interp/interp.c | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/mono/mini/arrays.cs b/mono/mini/arrays.cs index 00a3c6b901f..22140025538 100644 --- a/mono/mini/arrays.cs +++ b/mono/mini/arrays.cs @@ -768,6 +768,20 @@ class Tests return 0; } + public struct TestStruct { + } + + // #11603 + public static int test_0_ldelema () { + try { + TestStruct[] frames = null; + _ = frames[0]; + return 1; + } catch (NullReferenceException) { + return 0; + } + } + static bool alloc_long (long l) { try { var arr = new byte[l]; diff --git a/mono/mini/interp/interp.c b/mono/mini/interp/interp.c index 3ae33242b25..96f3194b1be 100644 --- a/mono/mini/interp/interp.c +++ b/mono/mini/interp/interp.c @@ -4776,6 +4776,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st sp -= numargs; o = sp [0].data.o; + if (!o) + THROW_EX (mono_get_exception_null_reference (), ip); sp->data.p = ves_array_element_address (frame, klass, (MonoArray *) o, &sp [1], needs_typecheck); if (frame->ex) THROW_EX (frame->ex, ip); |