From: Todd C. Miller Date: Fri, 5 Oct 2018 20:04:29 +0000 (-0600) Subject: Initialize the pty rows/cols based on the values we stored in user_details. X-Git-Tag: SUDO_1_8_26^2~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2570307e68e157a823a8c06004cecdcabe6442a;p=sudo Initialize the pty rows/cols based on the values we stored in user_details. This fixes a minor issue where we would send an extra window size change event the first time the command was suspended. --- diff --git a/src/exec_pty.c b/src/exec_pty.c index d906feb55..b89afd87c 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2017 Todd C. Miller + * Copyright (c) 2009-2018 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -58,6 +58,8 @@ struct exec_closure_pty { pid_t monitor_pid; pid_t cmnd_pid; pid_t ppgrp; + short rows; + short cols; struct command_status *cstat; struct command_details *details; struct sudo_event_base *evbase; @@ -1101,6 +1103,8 @@ fill_exec_closure_pty(struct exec_closure_pty *ec, struct command_status *cstat, ec->ppgrp = ppgrp; ec->cstat = cstat; ec->details = details; + ec->rows = user_details.ts_rows; + ec->cols = user_details.ts_cols; TAILQ_INIT(&ec->monitor_messages); /* Setup event base and events. */ @@ -1685,12 +1689,11 @@ del_io_events(bool nonblocking) static void sync_ttysize(struct exec_closure_pty *ec) { - static struct winsize owsize; struct winsize wsize; debug_decl(sync_ttysize, SUDO_DEBUG_EXEC); if (ioctl(io_fds[SFD_USERTTY], TIOCGWINSZ, &wsize) == 0) { - if (wsize.ws_row != owsize.ws_row || wsize.ws_col != owsize.ws_col) { + if (wsize.ws_row != ec->rows || wsize.ws_col != ec->cols) { const unsigned int wsize_packed = (wsize.ws_row & 0xffff) | ((wsize.ws_col & 0xffff) << 16); @@ -1700,8 +1703,9 @@ sync_ttysize(struct exec_closure_pty *ec) /* Send window change event to monitor process. */ send_command_status(ec, CMD_TTYWINCH, wsize_packed); - /* Update old value. */ - owsize = wsize; + /* Update rows/cols. */ + ec->rows = wsize.ws_row; + ec->cols = wsize.ws_col; } } diff --git a/src/sudo.c b/src/sudo.c index 5c2841c6e..604cd18ca 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -595,8 +595,8 @@ get_user_info(struct user_details *ud) goto oom; ud->host = user_info[i] + sizeof("host=") - 1; - sudo_get_ttysize(&ud->ts_lines, &ud->ts_cols); - if (asprintf(&user_info[++i], "lines=%d", ud->ts_lines) == -1) + sudo_get_ttysize(&ud->ts_rows, &ud->ts_cols); + if (asprintf(&user_info[++i], "lines=%d", ud->ts_rows) == -1) goto oom; if (asprintf(&user_info[++i], "cols=%d", ud->ts_cols) == -1) goto oom; diff --git a/src/sudo.h b/src/sudo.h index a2a4b5a5b..1d8e672dc 100644 --- a/src/sudo.h +++ b/src/sudo.h @@ -107,8 +107,8 @@ struct user_details { const char *shell; GETGROUPS_T *groups; int ngroups; + int ts_rows; int ts_cols; - int ts_lines; }; #define CD_SET_UID 0x00001