Skip to content

Commit 3b6b31c

Browse files
ashwinimurtjoncham
authored andcommitted
Prevent race during thread abort (case 1308625).
This field is normally protected by a lock. We don't need to ensure any consistent state between this and other data, only to ensure a single access for NULL or non-NULL to handle.
1 parent 704ddbc commit 3b6b31c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mono/metadata/threads.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4836,8 +4836,9 @@ MonoException*
48364836
mono_thread_get_undeniable_exception (void)
48374837
{
48384838
MonoInternalThread *thread = mono_thread_internal_current ();
4839+
MonoException *exc = (MonoException*)mono_atomic_cas_ptr ((volatile gpointer *)&thread->abort_exc, NULL, NULL);
48394840

4840-
if (!(thread && thread->abort_exc && !is_running_protected_wrapper ()))
4841+
if (!(thread && exc && !is_running_protected_wrapper ()))
48414842
return NULL;
48424843

48434844
// We don't want to have our exception effect calls made by
@@ -4850,9 +4851,9 @@ mono_thread_get_undeniable_exception (void)
48504851
* FIXME: Clear the abort exception and return an AppDomainUnloaded
48514852
* exception if the thread no longer references a dying appdomain.
48524853
*/
4853-
thread->abort_exc->trace_ips = NULL;
4854-
thread->abort_exc->stack_trace = NULL;
4855-
return thread->abort_exc;
4854+
exc->trace_ips = NULL;
4855+
exc->stack_trace = NULL;
4856+
return exc;
48564857
}
48574858

48584859
#if MONO_SMALL_CONFIG

0 commit comments

Comments
 (0)