--- rxvt-unicode/src/proxy.C 2007/01/16 18:25:51 1.5 +++ rxvt-unicode/src/proxy.C 2007/08/02 13:54:17 1.8 @@ -33,6 +33,7 @@ #include #include #include +#include // helper/proxy support @@ -125,7 +126,10 @@ { if (id) { - close (pty); + close_tty (); + + if (pty >= 0) + close (pty); NEED_TOKEN; @@ -294,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 ()