Always restore global environ if we use vfork

We may change the global environ variable in the child; when using
vfork() this also sets it in the parent.  Preserve the parent's
environ in child_execute_job() so it takes effect for all callers.

Reported by Denis Excoffier <bug-tar@Denis-Excoffier.org>
Root cause found by Martin Dorey <Martin.Dorey@hitachivantara.com>

* src/job.c (start_job_command): Remove save/restore of the parent
environment.
(child_execute_job): Add save/restore of the parent environment,
if we use vfork().
* tests/scripts/functions/shell: Add a test the crashes if we don't
reset environ after we run $(shell ...).
This commit is contained in:
Paul Smith
2022-09-25 13:29:59 -04:00
parent aa99e810a9
commit c4e232e44f
2 changed files with 24 additions and 12 deletions

View File

@@ -183,6 +183,15 @@ endif
!,
'--no-print-directory -j2 --jobserver-style=pipe', "#MAKE#[2]: warning: jobserver unavailable: using -j1. Add '+' to parent make rule.\n: 2\n: 1");
}
# This crashes if we use vfork and don't reset environ properly
run_make_test(q!
export PATH = $(shell echo "tests:$$PATH")
foo = $(shell echo yes)
all:;echo $(foo)
!,
'', "echo yes\nyes\n");
}
# If we're not using pipes for jobserver, then they are available in sub-makes