Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-07-22 22:23:35 +0400
committerJunio C Hamano <gitster@pobox.com>2013-07-22 22:23:35 +0400
commitcb29dfde484e459e4329281151b05ef1c5ad462c (patch)
tree7d99f8e0d925b8369757793d6a9f65d27691a4a5 /setup.c
parent5701c3d701d3932d853ffb9f75ee8745fae21209 (diff)
parenta11c39646c14600d588ca55fcfe3c244b66047c7 (diff)
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
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/setup.c b/setup.c
index 94c1e61bda..88aab94f15 100644
--- a/setup.c
+++ b/setup.c
@@ -908,3 +908,15 @@ const char *resolve_gitdir(const char *suspect)
return suspect;
return read_gitfile(suspect);
}
+
+/* if any standard file descriptor is missing open it to /dev/null */
+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);
+}