This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Avoid collect2 calling signal unsafe functions and/or unlink, with uninitialized memory (for gcc-8 branch)
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>, Jakub Jelinek <jakub at redhat dot com>
- Date: Wed, 19 Feb 2020 15:04:43 +0000
- Subject: [PATCH] Avoid collect2 calling signal unsafe functions and/or unlink, with uninitialized memory (for gcc-8 branch)
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CN1ASK4ZsVF/S29Z62sseDkZiDLVGqADamlgJoABWHM=; b=jlja1sa9CaTNJQCj6+zQ58lTMn9GQJYR4Ddzf7VlN5PMNuYnC/J+PwdCb7cu7cczN6Nn6k4QzuqRm02SExPp34ab5RDZIGcf2vyWOe2VvL0eQBb95cnucvfo46I9QbpCGw/Hla/5N+S3WvEESYqcp5mYKr1oZDNsIWXGmEfp62Mb0CD6vQNsAwDXNOEgOw6dx5rmEL/CsrycCbPRdDVKHBz4C48/VYH4lLgkr99ZXpB4qaHR0Wel7y0vkqt/EJ7fFWElX5y0N526sCzDv1t7MBf1x48tEVgqjn9UZ3PgQT2dvVrNBX9+igTbnxRJ8y5crliPLx8uHAs7uqYrq6LyHw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f0nvI4oNInw84HyqJJ0jQgzo5G0YbK2KgRdVjwphhnMKFE95vXiMMIonRWoeWH6tLLOuqwUDI/v6qapr7ZYrtLCTeYVGThkb9egYCosAPwPhcScHWnKxpUzheS7y2BBxLLFCI+DQdZ+4Wb9dvMOWQ+bPvPVt0Mc5ApKmeYXxeH0rW4iDSZAbEbk3r7mYMvbKIkl1D2LI2kaSNmxDPG64eumhEQXiiLfqKdLqkNMsW3Fbfej7/8Afe5shXPl5vk6bXCdge30SSnBFPwilIGpNj0i6IHBR3QKHS8qWepaolBnmnKLb1hx0Z//pEn6k9lfp61bRutm0Lo/TbIqshqxfhg==
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.
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