From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 0DA883858D1E; Tue, 24 Jan 2023 10:53:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DA883858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674557622; bh=94+6Dpsrdp7+x7Mdfdeluu4Lj/JQyrOxYHLApTHgaWg=; h=From:To:Subject:Date:From; b=UoIokABin1y2c0N6vQsPYD1uSfiC/qpa5l4fj01EXW4yyk25LggAdgU9gncXdP2tR jlM56ysymqb3lXqidPxd/ms6TVzpPEstpdkoV2kaZaP96OJEiUC5T0DYpUp1rvxJrC mKh7zD277cuRx6KCdxElUSJ1blZBcFRb6nhXZmPA= 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 r11-10479] driver: fix environ corruption after putenv() [PR106624] X-Act-Checkin: gcc X-Git-Author: Sergei Trofimovich X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 429699a4a80238cdbacdb66b34fef97c0455afd1 X-Git-Newrev: 9d21cc4edd94f8f2b1a3241fab5cf75649003226 Message-Id: <20230124105342.0DA883858D1E@sourceware.org> Date: Tue, 24 Jan 2023 10:53:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9d21cc4edd94f8f2b1a3241fab5cf75649003226 commit r11-10479-g9d21cc4edd94f8f2b1a3241fab5cf75649003226 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 795cf9eb01d..20a649ea08e 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -9077,7 +9077,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. */