From: Thomas Rast <trast@inf.ethz.ch>
To: <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
"Dale R. Worley" <worley@alum.mit.edu>
Subject: [PATCH 2/2] git: ensure 0/1/2 are open in main()
Date: Tue, 16 Jul 2013 11:27:37 +0200 [thread overview]
Message-ID: <65e2cdb28e76de8f669f3d58556fa9b8da944c5b.1373966758.git.trast@inf.ethz.ch> (raw)
In-Reply-To: <1fe4ff3df32aa1836ed3672e749f582047745bc9.1373966758.git.trast@inf.ethz.ch>
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>
---
git.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/git.c b/git.c
index 4359086..6104d5e 100644
--- a/git.c
+++ b/git.c
@@ -525,6 +525,13 @@ int main(int argc, char **av)
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();
/*
--
1.8.3.2.998.g1d087bc
prev parent reply other threads:[~2013-07-16 9:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-12 8:58 [PATCH 0/2] open() error checking Thomas Rast
2013-07-12 8:58 ` [PATCH 1/2] git_mkstemps: correctly test return value of open() Thomas Rast
2013-07-16 9:37 ` Thomas Rast
2013-07-17 19:29 ` Junio C Hamano
2013-07-18 12:32 ` Drew Northup
2013-07-18 17:46 ` Junio C Hamano
2013-07-18 17:47 ` Junio C Hamano
2013-07-18 20:32 ` Dale R. Worley
2013-07-18 20:49 ` Eric Sunshine
2013-07-18 20:54 ` Junio C Hamano
2013-07-18 22:46 ` Dale R. Worley
2013-07-18 23:23 ` Junio C Hamano
2013-07-18 23:29 ` Dale R. Worley
2013-07-12 8:58 ` [PATCH 2/2] run-command: dup_devnull(): guard against syscalls failing Thomas Rast
2013-07-12 17:29 ` [PATCH 0/2] open() error checking Junio C Hamano
2013-07-16 9:25 ` Thomas Rast
2013-07-16 9:27 ` [PATCH 1/2] daemon/shell: refactor redirection of 0/1/2 from /dev/null Thomas Rast
2013-07-16 9:27 ` Thomas Rast [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65e2cdb28e76de8f669f3d58556fa9b8da944c5b.1373966758.git.trast@inf.ethz.ch \
--to=trast@inf.ethz.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=worley@alum.mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).