Merge branch 'tr/protect-low-3-fds'
When "git" is spawned in such a way that any of the low 3 file descriptors is closed, our first open() may yield file descriptor 2, and writing error message to it would screw things up in a big way. * tr/protect-low-3-fds: git: ensure 0/1/2 are open in main() daemon/shell: refactor redirection of 0/1/2 from /dev/null
This commit is contained in:
12
daemon.c
12
daemon.c
@ -1047,18 +1047,6 @@ static int service_loop(struct socketlist *socklist)
|
||||
}
|
||||
}
|
||||
|
||||
/* if any standard file descriptor is missing open it to /dev/null */
|
||||
static void sanitize_stdfds(void)
|
||||
{
|
||||
int fd = open("/dev/null", O_RDWR, 0);
|
||||
while (fd != -1 && fd < 2)
|
||||
fd = dup(fd);
|
||||
if (fd == -1)
|
||||
die_errno("open /dev/null or dup failed");
|
||||
if (fd > 2)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
#ifdef NO_POSIX_GOODIES
|
||||
|
||||
struct credentials;
|
||||
|
Reference in New Issue
Block a user