[mono] Don't allow interfaces as catch classes to catch anything. (#73165)
authorZoltan Varga <vargaz@gmail.com>
Tue, 2 Aug 2022 06:09:30 +0000 (02:09 -0400)
committerGitHub <noreply@github.com>
Tue, 2 Aug 2022 06:09:30 +0000 (02:09 -0400)
Fixes https://github.com/dotnet/runtime/issues/72827.

src/mono/mono/mini/mini-exceptions.c
src/tests/issues.targets

index b67d752..746d8a2 100644 (file)
@@ -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
index 1cda405..e8236c2 100644 (file)
 
     <!-- Known failures for mono runtime on *all* architectures/operating systems in *all* runtime modes -->
     <ItemGroup Condition="'$(RuntimeFlavor)' == 'mono'" >
-        <ExcludeList Include = "$(XUnitTestBinBase)/JIT/Generics/Exceptions/GenericCatchInterfaceProgram/**">
-            <Issue>https://github.com/dotnet/runtime/issues/72827</Issue>
-        </ExcludeList>
         <ExcludeList Include = "$(XUnitTestBinBase)/JIT/Directed/Arrays/nintindexoutofrange/**">
             <Issue>https://github.com/dotnet/runtime/issues/71656</Issue>
         </ExcludeList>