From c05e3b1f3ad000f73284a2b3c6a283a287b3d05c Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 31 May 2012 19:14:56 +0000 Subject: [PATCH] Make sure to have file descriptors 0-2 open before doing further setup. Otherwise strange invocations could trick us into passing the event descriptor as, for example, stdin to the server. See PR 46463 for details. --- external/bsd/tmux/dist/tmux.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/external/bsd/tmux/dist/tmux.c b/external/bsd/tmux/dist/tmux.c index b5047392d63a..5ba7ed97daaf 100644 --- a/external/bsd/tmux/dist/tmux.c +++ b/external/bsd/tmux/dist/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.1.1.2 2011/08/17 18:40:05 jmmv Exp $ */ +/* $Id: tmux.c,v 1.2 2012/05/31 19:14:56 martin Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -213,6 +213,22 @@ shell_exec(const char *shell, const char *shellcmd) fatal("execl failed"); } +static void +init_std_fds(void) +{ + int fd; + + /* + * Make sure the standard file descriptors are populated, so we + * don't end up forwarding (for example) the event descriptor + * instead of stdin to the server. + */ + + while ((fd = open("/dev/null", O_RDWR)) <= 2) + ; + close(fd); +} + int main(int argc, char **argv) { @@ -283,6 +299,7 @@ main(int argc, char **argv) if (shell_cmd != NULL && argc != 0) usage(); + init_std_fds(); log_open_tty(debug_level); if (!(flags & IDENTIFY_UTF8)) {