ack/plat/pdpv7/libsys/isatty.c
George Koehler 5db312a1c0 Prevent crash in isatty()
The existing code allocated 2 bytes (char*), but gtty() needs 6 bytes
(struct sgttyb), so isatty() smashed the stack and corrupted its
return address, probably causing SIGBUS or SIGSEGV.

Fix by switching to TIOCGETD, which needs 2 bytes.  TIOCGETD isn't in
the manual for tty(4), but does appear in
https://minnie.tuhs.org//cgi-bin/utree.pl?file=V7/usr/sys/dev/tty.c

This fixes hilo_c.pdpv7 and hilo_mod.pdpv7 in simh-pdp11.
2018-06-15 00:48:29 -04:00

9 lines
125 B
C

int isatty(int fd)
{
unsigned u;
if (ioctl(fd, /*TIOCGETD*/(('t'<<8)|0), &u) < 0)
return 0;
return 1;
}