From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 05F963858D1E; Tue, 24 Jan 2023 10:55:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05F963858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674557705; bh=qS09Qekfy+8LeSTZkCdCwzI1cG1BAXHERtouJDJ4MFc=; h=From:To:Subject:Date:From; b=JTqKKNJBJX9NFf3ElE8b36sjRByF27O54XjKzicwogWzWr57ivOfxDdy/2OPEDjjy /VZNK2nMuhCKVk6jU4AGld8PkIdfhKFdUMTS6cJECOBG4Rstx85diWS9U7QNuGMoMz X5gbfro9QnLXJ5pZCYoU2PoLMQai8gUD/WNsXAJI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-11172] driver: fix environ corruption after putenv() [PR106624] X-Act-Checkin: gcc X-Git-Author: Sergei Trofimovich X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 1187b3b582e0c925d277022718b93cc12754de4c X-Git-Newrev: 6ced00d53d91ea429948b34e6600b4633f962030 Message-Id: <20230124105505.05F963858D1E@sourceware.org> Date: Tue, 24 Jan 2023 10:55:05 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6ced00d53d91ea429948b34e6600b4633f962030 commit r10-11172-g6ced00d53d91ea429948b34e6600b4633f962030 Author: Sergei Trofimovich Date: Tue Aug 16 12:35:07 2022 +0100 driver: fix environ corruption after putenv() [PR106624] The bug appeared afte r13-2010-g1270ccda70ca09 "Factor out jobserver_active_p" slightly changed `putenv()` use from allocating to non-allocating: -xputenv (concat ("MAKEFLAGS=", dup, NULL)); +xputenv (jinfo.skipped_makeflags.c_str ()); `xputenv()` (and `putenv()`) don't copy strings and only store the pointer in the `environ` global table. As a result `environ` got corrupted as soon as `jinfo.skipped_makeflags` store got deallocated. This started causing bootstrap crashes in `execv()` calls: xgcc: fatal error: cannot execute '/build/build/./prev-gcc/collect2': execv: Bad address The change restores memory allocation for `xputenv()` argument. gcc/ PR driver/106624 * gcc.c (driver::detect_jobserver): Allocate storage xputenv() argument using xstrdup(). (cherry picked from commit 2b403297b111c990c331b5bbb6165b061ad2259b) Diff: --- gcc/gcc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/gcc.c b/gcc/gcc.c index ed7099c2a6d..6517d9935dc 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -8403,7 +8403,7 @@ driver::detect_jobserver () const { jobserver_info jinfo; if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ()) - xputenv (jinfo.skipped_makeflags.c_str ()); + xputenv (xstrdup (jinfo.skipped_makeflags.c_str ())); } /* Determine what the exit code of the driver should be. */