Make sure backends can't break the network dialog and crash the remote net

backend by writing to stdin/stdout/stderr.
merge-requests/1/head
Julien BLACHE 2009-03-02 11:21:52 +00:00
rodzic 135ac7d1ac
commit b72c29cd75
2 zmienionych plików z 40 dodań i 0 usunięć

Wyświetl plik

@ -1,3 +1,8 @@
2009-03-02 Julien Blache <jb@jblache.org>
* frontend/saned.c: work around backends that can't keep their
dirty fingers off stdin/stdout/stderr when run through inetd,
breaking the network dialog and crashing the remote net backend.
2009-02-28 Chris Bagwell <cbagwell-guest at users.alioth.debian.org>
* m4/byteorder.m4: Delete temporary file in all cases.
* backend/Makefile.am, japi/Makefile.am: Use BUILT_SOURCES

Wyświetl plik

@ -3112,6 +3112,41 @@ static void
run_inetd (int argc, char **argv)
{
int fd = 1;
int dave_null;
/* Some backends really can't keep their dirty fingers off
* stdin/stdout/stderr; we work around them here so they don't
* mess up the network dialog and crash the remote net backend.
*/
do
{
fd = dup (fd);
if (fd == -1)
{
DBG (DBG_ERR, "run_inetd: duplicating fd failed: %s", strerror (errno));
return;
}
}
while (fd < 3);
/* Our good'ole friend Dave Null to the rescue */
dave_null = open ("/dev/null", O_RDWR);
if (dave_null < 0)
{
DBG (DBG_ERR, "run_inetd: could not open /dev/null: %s", strerror (errno));
return;
}
close (STDIN_FILENO);
close (STDOUT_FILENO);
close (STDERR_FILENO);
dup2 (dave_null, STDIN_FILENO);
dup2 (dave_null, STDOUT_FILENO);
dup2 (dave_null, STDERR_FILENO);
close (dave_null);
#ifndef HAVE_OS2_H
/* Unused in this function */