From e4dd880ee8a709298a6e7679ac7b64b796d0faa9 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Tue, 9 Aug 2022 19:32:58 +0300 Subject: [PATCH] [mono][interp] Return null for localloc with len 0 (#73174) so that accessing the result address throws exception. Fixes https://github.com/dotnet/runtime/issues/54359 --- src/mono/mono/mini/interp/interp.c | 11 ++++++++--- src/tests/issues.targets | 15 --------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index fc7e492778430..0c69d67bf6376 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -7127,10 +7127,15 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK; MINT_IN_CASE(MINT_LOCALLOC) { int len = LOCAL_VAR (ip [2], gint32); - gpointer mem = frame_data_allocator_alloc (&context->data_stack, frame, ALIGN_TO (len, MINT_VT_ALIGNMENT)); + gpointer mem; + if (len > 0) { + mem = frame_data_allocator_alloc (&context->data_stack, frame, ALIGN_TO (len, MINT_VT_ALIGNMENT)); - if (frame->imethod->init_locals) - memset (mem, 0, len); + if (frame->imethod->init_locals) + memset (mem, 0, len); + } else { + mem = NULL; + } LOCAL_VAR (ip [1], gpointer) = mem; ip += 3; MINT_IN_BREAK; diff --git a/src/tests/issues.targets b/src/tests/issues.targets index c4dd696bdbca1..61b04ec3db157 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -2504,9 +2504,6 @@ https://github.com/dotnet/runtime/issues/54393 - - https://github.com/dotnet/runtime/issues/54359 - needs triage @@ -2624,9 +2621,6 @@ needs triage - - https://github.com/dotnet/runtime/issues/54359 - needs triage @@ -2642,15 +2636,6 @@ https://github.com/dotnet/runtime/issues/54399 - - https://github.com/dotnet/runtime/issues/54359 - - - https://github.com/dotnet/runtime/issues/54359 - - - https://github.com/dotnet/runtime/issues/54359 - https://github.com/dotnet/runtime/issues/54393