Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/tmux/dist Make sure to have file descriptors 0-...



details:   https://anonhg.NetBSD.org/src/rev/3cbdd589aad1
branches:  trunk
changeset: 779504:3cbdd589aad1
user:      martin <martin%NetBSD.org@localhost>
date:      Thu May 31 19:14:56 2012 +0000

description:
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.

diffstat:

 external/bsd/tmux/dist/tmux.c |  19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diffs (40 lines):

diff -r 5161303778ed -r 3cbdd589aad1 external/bsd/tmux/dist/tmux.c
--- a/external/bsd/tmux/dist/tmux.c     Thu May 31 19:00:41 2012 +0000
+++ b/external/bsd/tmux/dist/tmux.c     Thu May 31 19:14:56 2012 +0000
@@ -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 <nicm%users.sourceforge.net@localhost>
@@ -213,6 +213,22 @@
        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 @@
        if (shell_cmd != NULL && argc != 0)
                usage();
 
+       init_std_fds();
        log_open_tty(debug_level);
 
        if (!(flags & IDENTIFY_UTF8)) {



Home | Main Index | Thread Index | Old Index