Instead of closing stderr, redirect it to /dev/null in
tunnel_socket_open(). Otherwise a program can accidentally open a
file into handle 2 and then unknowingly use that when trying to print
to stderr.
Thanks to lotheac for the original patch, which I just modified
slightly.
int pid;
int rc;
int pin[2], pout[2];
+ int devnull;
tunnel = (TUNNEL_DATA*) safe_malloc (sizeof (TUNNEL_DATA));
conn->sockdata = tunnel;
if ((pid = fork ()) == 0)
{
mutt_unblock_signals_system (0);
- if (dup2 (pout[0], STDIN_FILENO) < 0 || dup2 (pin[1], STDOUT_FILENO) < 0)
+ devnull = open ("/dev/null", O_RDWR);
+ if (devnull < 0 ||
+ dup2 (pout[0], STDIN_FILENO) < 0 ||
+ dup2 (pin[1], STDOUT_FILENO) < 0 ||
+ dup2 (devnull, STDERR_FILENO) < 0)
_exit (127);
close (pin[0]);
close (pin[1]);
close (pout[0]);
close (pout[1]);
- close (STDERR_FILENO);
+ close (devnull);
/* Don't let the subprocess think it can use the controlling tty */
setsid ();