Skip to content

Commit

Permalink
git: ensure 0/1/2 are open in main()
Browse files Browse the repository at this point in the history
Not having an open FD in the 0--2 range can lead to strange results,
for example, a subsequent open() may return 2 (stderr) and then a
die() would clobber this file.

git-daemon and git-shell already guarded against this, but apparently
users also manage to trip over it in other git commands.  So we call
sanitize_stdfds() during main git startup.

Since these FDs are inherited, this covers all use of 'git foo ...',
and all internal C commands when called directly.  It does not fix
shell/perl commands called directly.

Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Thomas Rast authored and Junio C Hamano committed Jul 17, 2013
1 parent 1d999dd commit a11c396
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ int main(int argc, const char **argv)
if (!cmd)
cmd = "git-help";

/*
* Always open file descriptors 0/1/2 to avoid clobbering files
* in die(). It also avoids messing up when the pipes are dup'ed
* onto stdin/stdout/stderr in the child processes we spawn.
*/
sanitize_stdfds();

git_setup_gettext();

/*
Expand Down

0 comments on commit a11c396

Please sign in to comment.