]> gcc.gnu.org Git - gcc.git/commit
driver: fix environ corruption after putenv() [PR106624]
authorSergei Trofimovich <siarheit@google.com>
Tue, 16 Aug 2022 11:35:07 +0000 (12:35 +0100)
committerMartin Liska <mliska@suse.cz>
Tue, 24 Jan 2023 10:52:07 +0000 (11:52 +0100)
commit193f7e62815b4089dfaed4c2bd34fd4f10209e27
tree6dea99899f978088d9d485fb0848f90cc20966ca
parent7ec291e86b2fce0e0d9f2f495af449f3c844bf6f
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.cc (driver::detect_jobserver): Allocate storage xputenv()
argument using xstrdup().

(cherry picked from commit 2b403297b111c990c331b5bbb6165b061ad2259b)
gcc/gcc.cc
This page took 0.063582 seconds and 6 git commands to generate.