--- rxvt-unicode/src/proxy.C 2006/01/25 22:09:33 1.3 +++ rxvt-unicode/src/proxy.C 2007/08/02 13:54:17 1.8 @@ -27,16 +27,17 @@ #include "ptytty.h" -// helper/proxy support - -#if PTYTTY_HELPER - #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 +126,11 @@ { if (id) { + close_tty (); + + if (pty >= 0) + close (pty); + NEED_TOKEN; command cmd; @@ -292,11 +298,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 ()