From 8389fcc4c1253fe11fd310284dcf31ac6c02a749 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Mon, 17 Feb 2020 17:40:07 +0100 Subject: [PATCH] Avoid collect2 calling signal unsafe functions and/or unlink with uninitialized memory 2020-02-24 Bernd Edlinger * collect2.c (tool_cleanup): Avoid calling not signal-safe functions. (maybe_run_lto_and_relink): Avoid possible signal handler access to unintialzed memory (lto_o_files). --- gcc/ChangeLog | 7 +++++++ gcc/collect2.c | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8d8dbc0bdff5..a79889e1bf20 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2020-02-24 Bernd Edlinger + + * collect2.c (tool_cleanup): Avoid calling not signal-safe + functions. + (maybe_run_lto_and_relink): Avoid possible signal handler + access to unintialzed memory (lto_o_files). + 2020-02-23 Peter Bergner Backport from master diff --git a/gcc/collect2.c b/gcc/collect2.c index eb84f84639be..8f092e7539ec 100644 --- a/gcc/collect2.c +++ b/gcc/collect2.c @@ -384,6 +384,10 @@ static void scan_prog_file (const char *, scanpass, scanfilter); void tool_cleanup (bool from_signal) { + /* maybe_unlink may call notice, which is not signal safe. */ + if (from_signal) + verbose = false; + if (c_file != 0 && c_file[0]) maybe_unlink (c_file); @@ -743,7 +747,10 @@ maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst, ++num_files; } - lto_o_files = XNEWVEC (char *, num_files + 1); + /* signal handler may access uninitialized memory + and delete whatever it points to, if lto_o_files + is not allocated with calloc. */ + lto_o_files = XCNEWVEC (char *, num_files + 1); lto_o_files[num_files] = NULL; start = XOBFINISH (&temporary_obstack, char *); for (i = 0; i < num_files; ++i) -- 2.47.2