From ad1f2685eb2768dbc2b52a9962d6279aa90a343d Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Mon, 22 Oct 2018 10:18:14 -0500 Subject: Don't call TIOCGWINSZ on non-ttys Prior to calling TIOCGWINSZ on stdin/stdout/stderr, check to see if the file descriptor is a tty. Calling TIOCGWINSZ on a non-tty doesn't make any sense. Calling TIOCGWINSZ on a non-tty is mildly problematic for systems like Android where strict ioctl filtering is in place, and generates SELinux audit noise. Strict ioctl filtering for non-filesystem fifo_files (eg pipe() or pipe2() generated pipes) was enabled in Android in commit https://android-review.googlesource.com/c/platform/system/sepolicy/+/792599 --- lib/interestingtimes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/interestingtimes.c b/lib/interestingtimes.c index 9cf84041..a1aa2b67 100644 --- a/lib/interestingtimes.c +++ b/lib/interestingtimes.c @@ -27,7 +27,7 @@ int terminal_size(unsigned *xx, unsigned *yy) // stdin, stdout, stderr for (i=0; i<3; i++) { memset(&ws, 0, sizeof(ws)); - if (!ioctl(i, TIOCGWINSZ, &ws)) { + if (isatty(i) && !ioctl(i, TIOCGWINSZ, &ws)) { if (ws.ws_col) x = ws.ws_col; if (ws.ws_row) y = ws.ws_row; -- cgit v1.2.3