--- rxvt-unicode/src/proxy.C 2007/01/16 18:25:51 1.5 +++ 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,16 +23,19 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *---------------------------------------------------------------------*/ -#include "../config.h" +#include "config.h" #include "ptytty.h" +#include +#include #include #include #include #include #include +#include // helper/proxy support @@ -125,7 +128,10 @@ { if (id) { - close (pty); + close_tty (); + + if (pty >= 0) + close (pty); NEED_TOKEN; @@ -294,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 ()