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.
This commit is contained in:
Todd C. Miller
2018-12-05 10:43:14 -07:00
parent 83fd48a75c
commit e91e5ee820

View File

@@ -354,6 +354,30 @@ sudo_terminated(struct command_status *cstat)
debug_return_bool(false); 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 * Execute a command, potentially in a pty with I/O loggging, and
* wait for it to finish. * 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 * 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. * 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)) if (exec_pty(details, cstat))
goto done; goto done;
} }