--- rxvt-unicode/src/proxy.C 2006/01/25 22:09:33 1.3 +++ rxvt-unicode/src/proxy.C 2011/02/21 07:41:02 1.11 @@ -6,7 +6,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2006 Marc Lehmann + * Copyright (c) 2006 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,20 +23,23 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *---------------------------------------------------------------------*/ -#include "../config.h" +#include "config.h" #include "ptytty.h" -// helper/proxy support - -#if PTYTTY_HELPER - +#include +#include #include #include #include #include #include +#include + +// helper/proxy support + +#if PTYTTY_HELPER static int sock_fd = -1, lock_fd = -1; static int helper_pid, owner_pid; @@ -125,6 +128,11 @@ { if (id) { + close_tty (); + + if (pty >= 0) + close (pty); + NEED_TOKEN; command cmd; @@ -292,11 +300,30 @@ } void +ptytty::sanitise_stdfd () +{ + // sanitise stdin/stdout/stderr to point to *something*. + for (int fd = 0; fd <= 2; ++fd) + if (fcntl (fd, F_GETFL) < 0 && errno == EBADF) + { + int fd2 = open ("/dev/tty", fd ? O_WRONLY : O_RDONLY); + + if (fd2 < 0) + fd2 = open ("/dev/null", fd ? O_WRONLY : O_RDONLY); + + if (fd2 != fd) + abort (); + } +} + +void ptytty::init () { + sanitise_stdfd (); + uid_t uid = getuid (); gid_t gid = getgid (); - + // before doing anything else, check for setuid/setgid operation, // start the helper process and drop privileges if (uid != geteuid ()