Skip to content

Commit

Permalink
Check whether stderr is a tty before trying TIOCGWINSZ.
Browse files Browse the repository at this point in the history
  • Loading branch information
millert committed Apr 16, 2023
1 parent ae12d18 commit 5650b43
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/util/ttysize.c
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5650b43

Please sign in to comment.