Fix crash in XNU when calling ttyname() on an invalid fd

This commit is contained in:
pancake 2018-10-08 00:01:29 +02:00
parent 15aff17004
commit 15ab430fdd

View File

@ -1132,7 +1132,7 @@ R_API int r_cons_get_size(int *rows) {
struct winsize win = { 0 };
if (isatty (0) && !ioctl (0, TIOCGWINSZ, &win)) {
if ((!win.ws_col) || (!win.ws_row)) {
const char *tty = ttyname (1);
const char *tty = isatty (1)? ttyname (1): NULL;
int fd = open (tty? tty: "/dev/tty", O_RDONLY);
if (fd != -1) {
int ret = ioctl (fd, TIOCGWINSZ, &win);