From 0ef117e33e711950b0e6ac41c8fdb87503167e75 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Tue, 2 Aug 2022 02:09:30 -0400 Subject: [PATCH] [mono] Don't allow interfaces as catch classes to catch anything. (#73165) Fixes https://github.com/dotnet/runtime/issues/72827. --- src/mono/mono/mini/mini-exceptions.c | 3 ++- src/tests/issues.targets | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mono/mono/mini/mini-exceptions.c b/src/mono/mono/mini/mini-exceptions.c index b67d752..746d8a2 100644 --- a/src/mono/mono/mini/mini-exceptions.c +++ b/src/mono/mono/mini/mini-exceptions.c @@ -2043,7 +2043,7 @@ handle_exception_first_pass (MonoContext *ctx, MonoObject *obj, gint32 *out_filt } ERROR_DECL (isinst_error); // FIXME not used https://github.com/mono/mono/pull/3055/files#r240548187 - if (ei->flags == MONO_EXCEPTION_CLAUSE_NONE && mono_object_isinst_checked (ex_obj, catch_class, error)) { + if (ei->flags == MONO_EXCEPTION_CLAUSE_NONE && !MONO_CLASS_IS_INTERFACE_INTERNAL (catch_class) && mono_object_isinst_checked (ex_obj, catch_class, error)) { /* runtime invokes catch even unhandled exceptions */ setup_stack_trace (mono_ex, &dynamic_methods, trace_ips, method->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE); g_list_free (trace_ips); @@ -2422,6 +2422,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu error_init (error); if ((ei->flags == MONO_EXCEPTION_CLAUSE_NONE && + !MONO_CLASS_IS_INTERFACE_INTERNAL (catch_class) && mono_object_isinst_checked (ex_obj, catch_class, error)) || filtered) { /* * This guards against the situation that we abort a thread that is executing a finally clause diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 1cda405..e8236c2 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1436,9 +1436,6 @@ - - https://github.com/dotnet/runtime/issues/72827 - https://github.com/dotnet/runtime/issues/71656 -- 2.7.4