Permalink
Browse files

Closes GH-734 Do the setuid() after chdir()

1 parent 4a34692 commit bc8e9b340dd17ea5756c2ff0374763d9906efc92 @isaacs isaacs committed with ry Feb 28, 2011
Showing with 30 additions and 28 deletions.
  1. +30 −28 src/node_child_process.cc
@@ -327,6 +327,36 @@ int ChildProcess::Spawn(const char *file,
_exit(127);
}
+ if (custom_fds[0] == -1) {
+ close(stdin_pipe[1]); // close write end
+ dup2(stdin_pipe[0], STDIN_FILENO);
+ } else {
+ ResetFlags(custom_fds[0]);
+ dup2(custom_fds[0], STDIN_FILENO);
+ }
+
+ if (custom_fds[1] == -1) {
+ close(stdout_pipe[0]); // close read end
+ dup2(stdout_pipe[1], STDOUT_FILENO);
+ } else {
+ ResetFlags(custom_fds[1]);
+ dup2(custom_fds[1], STDOUT_FILENO);
+ }
+
+ if (custom_fds[2] == -1) {
+ close(stderr_pipe[0]); // close read end
+ dup2(stderr_pipe[1], STDERR_FILENO);
+ } else {
+ ResetFlags(custom_fds[2]);
+ dup2(custom_fds[2], STDERR_FILENO);
+ }
+
+ if (strlen(cwd) && chdir(cwd)) {
+ perror("chdir()");
+ _exit(127);
+ }
+
+
static char buf[PATH_MAX + 1];
int gid = -1;
@@ -380,34 +410,6 @@ int ChildProcess::Spawn(const char *file,
}
- if (custom_fds[0] == -1) {
- close(stdin_pipe[1]); // close write end
- dup2(stdin_pipe[0], STDIN_FILENO);
- } else {
- ResetFlags(custom_fds[0]);
- dup2(custom_fds[0], STDIN_FILENO);
- }
-
- if (custom_fds[1] == -1) {
- close(stdout_pipe[0]); // close read end
- dup2(stdout_pipe[1], STDOUT_FILENO);
- } else {
- ResetFlags(custom_fds[1]);
- dup2(custom_fds[1], STDOUT_FILENO);
- }
-
- if (custom_fds[2] == -1) {
- close(stderr_pipe[0]); // close read end
- dup2(stderr_pipe[1], STDERR_FILENO);
- } else {
- ResetFlags(custom_fds[2]);
- dup2(custom_fds[2], STDERR_FILENO);
- }
-
- if (strlen(cwd) && chdir(cwd)) {
- perror("chdir()");
- _exit(127);
- }
environ = env;

0 comments on commit bc8e9b3

Please sign in to comment.