Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for heap_use_after_free flagged by sanitizer #54679

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/mono/mono/mini/mini-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,31 @@ mono_runtime_shutdown_handlers (void)
static GHashTable *mono_saved_signal_handlers = NULL;

static struct sigaction *
get_saved_signal_handler (int signo, gboolean remove)
get_saved_signal_handler (int signo)
{
if (mono_saved_signal_handlers) {
/* The hash is only modified during startup, so no need for locking */
struct sigaction *handler = (struct sigaction*)g_hash_table_lookup (mono_saved_signal_handlers, GINT_TO_POINTER (signo));
if (remove && handler)
g_hash_table_remove (mono_saved_signal_handlers, GINT_TO_POINTER (signo));
return handler;
}
return NULL;
}


static void
remove_saved_signal_handler (int signo)
{
if (mono_saved_signal_handlers) {
/* The hash is only modified during startup, so no need for locking */
struct sigaction *handler = (struct sigaction*)g_hash_table_lookup (mono_saved_signal_handlers, GINT_TO_POINTER (signo));
if (handler)
g_hash_table_remove (mono_saved_signal_handlers, GINT_TO_POINTER (signo));
}
return;
}



static void
save_old_signal_handler (int signo, struct sigaction *old_action)
{
Expand Down Expand Up @@ -181,7 +194,7 @@ gboolean
MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal)
{
int signal = MONO_SIG_HANDLER_GET_SIGNO ();
struct sigaction *saved_handler = (struct sigaction *)get_saved_signal_handler (signal, FALSE);
struct sigaction *saved_handler = (struct sigaction *)get_saved_signal_handler (signal);

if (saved_handler && saved_handler->sa_handler) {
if (!(saved_handler->sa_flags & SA_SIGINFO)) {
Expand Down Expand Up @@ -376,7 +389,7 @@ static void
remove_signal_handler (int signo)
{
struct sigaction sa;
struct sigaction *saved_action = get_saved_signal_handler (signo, TRUE);
struct sigaction *saved_action = get_saved_signal_handler (signo);

if (!saved_action) {
sa.sa_handler = SIG_DFL;
Expand All @@ -387,6 +400,7 @@ remove_signal_handler (int signo)
} else {
g_assert (sigaction (signo, saved_action, NULL) != -1);
}
remove_saved_signal_handler(signo);
}

void
Expand Down