From: Todd C. Miller Date: Wed, 5 Dec 2018 17:43:14 +0000 (-0700) Subject: Don't run the command in a pty if no I/O plugins are logging anything. X-Git-Tag: SUDO_1_8_27^2~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e91e5ee820355e96826323bc1f021dff04c7e4b6;p=sudo Don't run the command in a pty if no I/O plugins are logging anything. That way an I/O plugin that doesn't actually log anything won't cause the command to be run in a pty. --- diff --git a/src/exec.c b/src/exec.c index 6799fc085..28d847d33 100644 --- a/src/exec.c +++ b/src/exec.c @@ -354,6 +354,30 @@ sudo_terminated(struct command_status *cstat) debug_return_bool(false); } +#if SUDO_API_VERSION != SUDO_API_MKVERSION(1, 13) +# error "Update sudo_needs_pty() after changing the plugin API" +#endif +static bool +sudo_needs_pty(struct command_details *details) +{ + struct plugin_container *plugin; + + if (ISSET(details->flags, CD_USE_PTY)) + return true; + + TAILQ_FOREACH(plugin, &io_plugins, entries) { + if (plugin->u.io->log_ttyin != NULL || + plugin->u.io->log_ttyout != NULL || + plugin->u.io->log_stdin != NULL || + plugin->u.io->log_stdout != NULL || + plugin->u.io->log_stderr != NULL || + plugin->u.io->change_winsize != NULL || + plugin->u.io->log_suspend != NULL) + return true; + } + return false; +} + /* * Execute a command, potentially in a pty with I/O loggging, and * wait for it to finish. @@ -389,7 +413,7 @@ sudo_execute(struct command_details *details, struct command_status *cstat) * has requested a pty. If /dev/tty is unavailable and no I/O plugin * is configured, this returns false and we run the command without a pty. */ - if (!TAILQ_EMPTY(&io_plugins) || ISSET(details->flags, CD_USE_PTY)) { + if (sudo_needs_pty(details)) { if (exec_pty(details, cstat)) goto done; }