summaryrefslogtreecommitdiff
path: root/runtime/utils.cc
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2016-08-30 17:15:26 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2016-08-30 17:15:26 +0000
commitd7eabc2cc1a88c1f7f927da61246ae65aab0626c (patch)
treedc61a7fd80e1289777f6a991102b0fe4a2ef032d /runtime/utils.cc
parent99fd9f39f2cd74864bdc750a3444ddd776da534c (diff)
parentd106d9f871c957286ccdeb79c1c2a5ed41f859a6 (diff)
Merge "Save environment snapshot and use at fork/exec"
Diffstat (limited to 'runtime/utils.cc')
-rw-r--r--runtime/utils.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/runtime/utils.cc b/runtime/utils.cc
index b676ae5ae5..313190c84d 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -1155,8 +1155,15 @@ int ExecAndReturnCode(std::vector<std::string>& arg_vector, std::string* error_m
// change process groups, so we don't get reaped by ProcessManager
setpgid(0, 0);
- execv(program, &args[0]);
- PLOG(ERROR) << "Failed to execv(" << command_line << ")";
+ // (b/30160149): protect subprocesses from modifications to LD_LIBRARY_PATH, etc.
+ // Use the snapshot of the environment from the time the runtime was created.
+ char** envp = (Runtime::Current() == nullptr) ? nullptr : Runtime::Current()->GetEnvSnapshot();
+ if (envp == nullptr) {
+ execv(program, &args[0]);
+ } else {
+ execve(program, &args[0], envp);
+ }
+ PLOG(ERROR) << "Failed to execve(" << command_line << ")";
// _exit to avoid atexit handlers in child.
_exit(1);
} else {