public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-8270] Avoid collect2 calling signal unsafe functions and/or unlink with uninitialized memory
@ 2020-02-24 13:44 Bernd Edlinger
  0 siblings, 0 replies; only message in thread
From: Bernd Edlinger @ 2020-02-24 13:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8389fcc4c1253fe11fd310284dcf31ac6c02a749

commit r9-8270-g8389fcc4c1253fe11fd310284dcf31ac6c02a749
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Mon Feb 17 17:40:07 2020 +0100

    Avoid collect2 calling signal unsafe functions and/or unlink with uninitialized memory
    
    2020-02-24  Bernd Edlinger  <bernd.edlinger@hotmail.de>
    
    	* 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).

Diff:
---
 gcc/ChangeLog  | 7 +++++++
 gcc/collect2.c | 9 ++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8d8dbc0..a79889e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2020-02-24  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+	* 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 <bergner@linux.ibm.com>
 
 	Backport from master
diff --git a/gcc/collect2.c b/gcc/collect2.c
index eb84f84..8f092e7 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)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-24 13:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 13:44 [gcc r9-8270] Avoid collect2 calling signal unsafe functions and/or unlink with uninitialized memory Bernd Edlinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).