summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <Todd.Miller@sudo.ws>2023-04-17 07:27:05 -0600
committerTodd C. Miller <Todd.Miller@sudo.ws>2023-04-17 07:27:05 -0600
commitacce6fe718a98046a7acd0ac20779358086e682e (patch)
tree2aca7d2078d076835234b92ebe66d6f59d35119f
parent0cdb70bada6986acd2a6d92743c2aa4019d95d4e (diff)
downloadsudo-acce6fe718a98046a7acd0ac20779358086e682e.tar.gz
get_user_info: call sudo_get_ttysize() even if no /dev/tty
We still want to initialize rows and cols based on the environment if possible.
-rw-r--r--lib/util/ttysize.c2
-rw-r--r--src/sudo.c12
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/util/ttysize.c b/lib/util/ttysize.c
index d72f96eb9..d7f515db4 100644
--- a/lib/util/ttysize.c
+++ b/lib/util/ttysize.c
@@ -39,7 +39,7 @@ get_ttysize_ioctl(int fd, int *rowp, int *colp)
struct winsize wsize;
debug_decl(get_ttysize_ioctl, SUDO_DEBUG_UTIL);
- if (isatty(fd) && ioctl(fd, TIOCGWINSZ, &wsize) == 0) {
+ if (fd != -1 && isatty(fd) && ioctl(fd, TIOCGWINSZ, &wsize) == 0) {
if (wsize.ws_row != 0 && wsize.ws_col != 0) {
*rowp = wsize.ws_row;
*colp = wsize.ws_col;
diff --git a/src/sudo.c b/src/sudo.c
index ebbc4e9bb..288b6970a 100644
--- a/src/sudo.c
+++ b/src/sudo.c
@@ -505,7 +505,7 @@ get_user_info(struct user_details *ud)
unsigned int i = 0;
mode_t mask;
struct passwd *pw;
- int fd, n;
+ int ttyfd, n;
debug_decl(get_user_info, SUDO_DEBUG_UTIL);
/*
@@ -531,12 +531,12 @@ get_user_info(struct user_details *ud)
ud->pid = getpid();
ud->ppid = getppid();
ud->pgid = getpgid(0);
- fd = open(_PATH_TTY, O_RDWR);
- if (fd != -1) {
- sudo_get_ttysize(fd, &ud->ts_rows, &ud->ts_cols);
- if ((ud->tcpgid = tcgetpgrp(fd)) == -1)
+ ttyfd = open(_PATH_TTY, O_RDWR);
+ sudo_get_ttysize(ttyfd, &ud->ts_rows, &ud->ts_cols);
+ if (ttyfd != -1) {
+ if ((ud->tcpgid = tcgetpgrp(ttyfd)) == -1)
ud->tcpgid = 0;
- close(fd);
+ close(ttyfd);
}
if ((ud->sid = getsid(0)) == -1)
ud->sid = 0;