Avoid collect2 calling signal unsafe functions and/or unlink, with uninitialized memory (for gcc-8 branch)

Message ID AM6PR03MB51707B75EF776B61151AF3AFE4100@AM6PR03MB5170.eurprd03.prod.outlook.com
State Superseded
Headers show
Series
  • Avoid collect2 calling signal unsafe functions and/or unlink, with uninitialized memory (for gcc-8 branch)
Related show

Commit Message

Bernd Edlinger Feb. 19, 2020, 3:04 p.m.
Hi,

this fixes the signal handler calling signal unsafe vfprintf and/or passing
uninitialized memory to unlink in signal handler.

This is the patch for the gcc-8 branch.


Bootstrapped and reg-tested with x86_64-pc-linux-gnu.
Is it OK for the gcc-8 branch?


Thanks
Bernd.

Comments

Richard Biener Feb. 20, 2020, 1:31 p.m. | #1
On Wed, 19 Feb 2020, Bernd Edlinger wrote:

> Hi,

> 

> this fixes the signal handler calling signal unsafe vfprintf and/or passing

> uninitialized memory to unlink in signal handler.

> 

> This is the patch for the gcc-8 branch.

> 

> 

> Bootstrapped and reg-tested with x86_64-pc-linux-gnu.

> Is it OK for the gcc-8 branch?


OK.

Richard.

> 

> Thanks

> Bernd.

> 


-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Patch

From dd98fe7c45c5096dfab9425dce6e0f88f5ccdcbe Mon Sep 17 00:00:00 2001
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
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-19  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).
---
 gcc/collect2.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index a96af13..11e3a39 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -382,6 +382,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)
+    debug = false;
+
   if (c_file != 0 && c_file[0])
     maybe_unlink (c_file);
 
@@ -741,7 +745,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 allocatted 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)
-- 
1.9.1