summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <Todd.Miller@sudo.ws>2023-04-16 15:31:14 -0600
committerTodd C. Miller <Todd.Miller@sudo.ws>2023-04-16 15:31:14 -0600
commita96a7bb7d416bf5e2e42ae3089afae9569873b9c (patch)
tree91bcd2c4bc2c8a0af551b45b0238064881bf6881
parent01cd1bfce0651c78fd29a0b283d0868cfe8e22be (diff)
downloadsudo-a96a7bb7d416bf5e2e42ae3089afae9569873b9c.tar.gz
Check whether stderr is a tty before trying TIOCGWINSZ.
-rw-r--r--lib/util/ttysize.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/util/ttysize.c b/lib/util/ttysize.c
index 221ea92b5..c14e3a85d 100644
--- a/lib/util/ttysize.c
+++ b/lib/util/ttysize.c
@@ -39,11 +39,12 @@ get_ttysize_ioctl(int *rowp, int *colp)
struct winsize wsize;
debug_decl(get_ttysize_ioctl, SUDO_DEBUG_UTIL);
- if (ioctl(STDERR_FILENO, TIOCGWINSZ, &wsize) == 0 &&
- wsize.ws_row != 0 && wsize.ws_col != 0) {
- *rowp = wsize.ws_row;
- *colp = wsize.ws_col;
- debug_return_int(0);
+ if (isatty(STDERR_FILENO) && ioctl(STDERR_FILENO, TIOCGWINSZ, &wsize) == 0) {
+ if (wsize.ws_row != 0 && wsize.ws_col != 0) {
+ *rowp = wsize.ws_row;
+ *colp = wsize.ws_col;
+ debug_return_int(0);
+ }
}
debug_return_int(-1);
}