Module Name: src Committed By: martin Date: Thu May 31 19:14:56 UTC 2012
Modified Files: src/external/bsd/tmux/dist: tmux.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.1.1.2 -r1.2 src/external/bsd/tmux/dist/tmux.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/tmux/dist/tmux.c diff -u src/external/bsd/tmux/dist/tmux.c:1.1.1.2 src/external/bsd/tmux/dist/tmux.c:1.2 --- src/external/bsd/tmux/dist/tmux.c:1.1.1.2 Wed Aug 17 18:40:05 2011 +++ src/external/bsd/tmux/dist/tmux.c Thu May 31 19:14:56 2012 @@ -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 <n...@users.sourceforge.net> @@ -213,6 +213,22 @@ shell_exec(const char *shell, const char 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)) {