From a2e541aef8f39eb746e3e5ed605f42a8481ca87f Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 16 May 2016 11:17:20 -0600 Subject: [PATCH] O_NOCTTY has no effect when opening /dev/tty as the open can only succeed if there is already a controlling tty. --- plugins/sudoers/sudoers.c | 2 +- src/exec.c | 2 +- src/exec_pty.c | 2 +- src/sudo.c | 2 +- src/tgetpass.c | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 5f33c2889..9d7991e40 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -1298,7 +1298,7 @@ tty_present(void) #if defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__) return user_ttypath != NULL; #else - int fd = open(_PATH_TTY, O_RDWR|O_NOCTTY); + int fd = open(_PATH_TTY, O_RDWR); if (fd != -1) close(fd); return fd != -1; diff --git a/src/exec.c b/src/exec.c index 0a6f7471c..3cdf92fc5 100644 --- a/src/exec.c +++ b/src/exec.c @@ -562,7 +562,7 @@ dispatch_signal(struct sudo_event_base *evbase, pid_t child, sigaction_t sa, osa; pid_t saved_pgrp = -1; int signo = WSTOPSIG(status); - int fd = open(_PATH_TTY, O_RDWR|O_NOCTTY, 0); + int fd = open(_PATH_TTY, O_RDWR); if (fd != -1) { saved_pgrp = tcgetpgrp(fd); if (saved_pgrp == -1) { diff --git a/src/exec_pty.c b/src/exec_pty.c index 369f2b543..368b31e9b 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -181,7 +181,7 @@ pty_setup(uid_t uid, const char *tty, const char *utmp_user) { debug_decl(pty_setup, SUDO_DEBUG_EXEC); - io_fds[SFD_USERTTY] = open(_PATH_TTY, O_RDWR|O_NOCTTY, 0); + io_fds[SFD_USERTTY] = open(_PATH_TTY, O_RDWR); if (io_fds[SFD_USERTTY] != -1) { if (!get_pty(&io_fds[SFD_MASTER], &io_fds[SFD_SLAVE], slavename, sizeof(slavename), uid)) diff --git a/src/sudo.c b/src/sudo.c index d4bd688c3..005596d6d 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -506,7 +506,7 @@ get_user_info(struct user_details *ud) ud->ppid = getppid(); ud->pgid = getpgid(0); ud->tcpgid = -1; - fd = open(_PATH_TTY, O_RDWR|O_NOCTTY, 0); + fd = open(_PATH_TTY, O_RDWR); if (fd != -1) { ud->tcpgid = tcgetpgrp(fd); close(fd); diff --git a/src/tgetpass.c b/src/tgetpass.c index 671c021d8..9b94c0e2b 100644 --- a/src/tgetpass.c +++ b/src/tgetpass.c @@ -125,7 +125,7 @@ restart: need_restart = 0; /* Open /dev/tty for reading/writing if possible else use stdin/stderr. */ if (ISSET(flags, TGP_STDIN) || - (input = output = open(_PATH_TTY, O_RDWR|O_NOCTTY)) == -1) { + (input = output = open(_PATH_TTY, O_RDWR)) == -1) { input = STDIN_FILENO; output = STDERR_FILENO; } @@ -372,7 +372,7 @@ tty_present(void) int fd; debug_decl(tty_present, SUDO_DEBUG_UTIL) - if ((fd = open(_PATH_TTY, O_RDWR|O_NOCTTY)) != -1) + if ((fd = open(_PATH_TTY, O_RDWR)) != -1) close(fd); debug_return_bool(fd != -1); #endif -- 2.40.0