Work around a GNO kernel bug that could cause crashes in error cases.

The issue is that the kernel's pty structures get corrupted if the master side of a pty is opened and then closed without the slave side having been opened. This can happen with telnetd in various error cases. The workaround is to arrange for the slave side to be opened just before telnetd exits in those cases.
This commit is contained in:
Stephen Heumann 2016-01-09 14:50:21 -06:00
parent 8a3b1e25cd
commit e6c2831323

View File

@ -375,6 +375,24 @@ spcset(int func, cc_t *valp, cc_t **valpp)
} }
#endif /* USE_TERMIO */ #endif /* USE_TERMIO */
static int slave_opened = 0;
#ifdef __GNO__
/*
* open_slave_at_exit()
*
* Called at exit. Works around a GNO kernel bug by ensuring that
* the slave side of the pty is opened before the master is closed.
*/
static void
open_slave_at_exit(void)
{
if (!slave_opened)
open(line, O_RDWR);
}
#endif /* __GNO__ */
/* /*
* getpty() * getpty()
* *
@ -407,6 +425,9 @@ getpty(int *ptynum __unused)
if (strlcpy(line, pn, sizeof line) >= sizeof line) if (strlcpy(line, pn, sizeof line) >= sizeof line)
return (-1); return (-1);
#ifdef __GNO__
atexit(open_slave_at_exit);
#endif
return (p); return (p);
} }
@ -924,6 +945,7 @@ cleanopen(char *li)
if (t < 0) if (t < 0)
return(-1); return(-1);
slave_opened = 1;
return(t); return(t);
} }