From 15ab430fdd0592d6b2bc1860f3010dc3ad1bda58 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 8 Oct 2018 00:01:29 +0200 Subject: [PATCH] Fix crash in XNU when calling ttyname() on an invalid fd --- libr/cons/cons.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/cons/cons.c b/libr/cons/cons.c index 91f9a0b05f..daf2029073 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -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);