Don't allow child process to clobber environ

v0.7.4-release
Ryan Dahl 2010-03-03 15:34:57 -08:00
parent d1500cee6e
commit d5ee777af2
1 changed files with 7 additions and 0 deletions

View File

@ -302,6 +302,10 @@ int ChildProcess::Spawn(const char *file, char *const args[], char **env) {
return -3;
}
// Save environ in the case that we get it clobbered
// by the child process.
char **save_our_env = environ;
switch (pid_ = vfork()) {
case -1: // Error.
Shutdown();
@ -324,6 +328,9 @@ int ChildProcess::Spawn(const char *file, char *const args[], char **env) {
_exit(127);
}
// Restore environment.
environ = save_our_env;
// Parent.
ev_child_set(&child_watcher_, pid_, 0);