mirror of
https://github.com/NixOS/nix.git
synced 2025-12-16 14:01:05 +01:00
Fix nix-build.cc double getenv("TZ") race condition
This is mostly theoretical, but the code was calling getenv("TZ")
twice: once to check if it's non-null, and again to get its value.
This creates a potential race condition where the environment could
change between calls.
This commit is contained in:
parent
de6fdb7da5
commit
76c09bf3d4
1 changed files with 3 additions and 1 deletions
|
|
@ -613,6 +613,8 @@ static void main_nix_build(int argc, char ** argv)
|
|||
environment variables and shell functions. Also don't
|
||||
lose the current $PATH directories. */
|
||||
auto rcfile = (tmpDir.path() / "rc").string();
|
||||
auto tz = getEnv("TZ");
|
||||
auto tzExport = tz ? "export TZ=" + escapeShellArgAlways(*tz) + "; " : "";
|
||||
std::string rc = fmt(
|
||||
(R"(_nix_shell_clean_tmpdir() { command rm -rf %1%; };)"s
|
||||
"trap _nix_shell_clean_tmpdir EXIT; "
|
||||
|
|
@ -646,7 +648,7 @@ static void main_nix_build(int argc, char ** argv)
|
|||
(pure ? "" : "PATH=$PATH:$p; unset p; "),
|
||||
escapeShellArgAlways(dirOf(*shell)),
|
||||
escapeShellArgAlways(*shell),
|
||||
(getenv("TZ") ? (std::string("export TZ=") + escapeShellArgAlways(getenv("TZ")) + "; ") : ""),
|
||||
tzExport,
|
||||
envCommand);
|
||||
vomit("Sourcing nix-shell with file %s and contents:\n%s", rcfile, rc);
|
||||
writeFile(rcfile, rc);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue