From 3b88cdfcd8d1a39eabbb5b7d0c8fe8f035d7a264 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 26 Sep 2017 14:21:11 -0600 Subject: [PATCH] Fix stair-stepped output when the output of a sudo command is piped to another command and use_pty is set. --- include/sudo_compat.h | 6 ++++++ src/exec_pty.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/include/sudo_compat.h b/include/sudo_compat.h index bbf8736a9..4c99c1234 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -164,6 +164,9 @@ #ifndef _S_IFLNK # define _S_IFLNK S_IFLNK #endif /* _S_IFLNK */ +#ifndef _S_IFIFO +# define _S_IFIFO S_IFIFO +#endif /* _S_IFIFO */ #ifndef S_ISREG # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) #endif /* S_ISREG */ @@ -173,6 +176,9 @@ #ifndef S_ISLNK # define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) #endif /* S_ISLNK */ +#ifndef S_ISFIFO +# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) +#endif /* S_ISLNK */ #ifndef S_ISTXT # define S_ISTXT 0001000 #endif /* S_ISTXT */ diff --git a/src/exec_pty.c b/src/exec_pty.c index 61a9fdc03..f55506655 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -1159,6 +1160,7 @@ exec_pty(struct command_details *details, struct command_status *cstat) struct plugin_container *plugin; sigset_t set, oset; struct sigaction sa; + struct stat sb; pid_t ppgrp; int sv[2]; debug_decl(exec_pty, SUDO_DEBUG_EXEC) @@ -1259,6 +1261,8 @@ exec_pty(struct command_details *details, struct command_status *cstat) /* Not logging stdin, do not interpose. */ sudo_debug_printf(SUDO_DEBUG_INFO, "stdin not a tty, not logging"); + if (fstat(STDIN_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode)) + pipeline = true; io_fds[SFD_STDIN] = dup(STDIN_FILENO); if (io_fds[SFD_STDIN] == -1) sudo_fatal("dup"); @@ -1278,6 +1282,8 @@ exec_pty(struct command_details *details, struct command_status *cstat) /* Not logging stdout, do not interpose. */ sudo_debug_printf(SUDO_DEBUG_INFO, "stdout not a tty, not logging"); + if (fstat(STDOUT_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode)) + pipeline = true; io_fds[SFD_STDOUT] = dup(STDOUT_FILENO); if (io_fds[SFD_STDOUT] == -1) sudo_fatal("dup"); @@ -1297,6 +1303,8 @@ exec_pty(struct command_details *details, struct command_status *cstat) /* Not logging stderr, do not interpose. */ sudo_debug_printf(SUDO_DEBUG_INFO, "stderr not a tty, not logging"); + if (fstat(STDERR_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode)) + pipeline = true; io_fds[SFD_STDERR] = dup(STDERR_FILENO); if (io_fds[SFD_STDERR] == -1) sudo_fatal("dup"); -- 2.40.0