From d5ee777af2b6a89ab866c74171f6059c85079f88 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 3 Mar 2010 15:34:57 -0800 Subject: [PATCH] Don't allow child process to clobber environ --- src/node_child_process.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/node_child_process.cc b/src/node_child_process.cc index 6902455dd0..6c09ee0f00 100644 --- a/src/node_child_process.cc +++ b/src/node_child_process.cc @@ -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);