From 1641c30ed63b5f73dba049b6527c89a11667293d Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 22 Feb 2023 10:55:27 -0700 Subject: [PATCH] visudo: quiet a compiler warning on Solaris 10. Also explicitly close /dev/tty fd instead of relying on closefrom() in case the fd ends up being a value 0-2. --- plugins/sudoers/visudo.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 24bf543b1..fea18933e 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -911,10 +911,13 @@ run_command(const char *path, char *const *argv, bool foreground) pid = getpid(); setpgid(0, pid); fd = open(_PATH_TTY, O_RDWR); - if (fd != -1 && tcsetpgrp(fd, pid) == -1) { - sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO, - "%s: unable to set foreground pgrp to %d (editor)", - __func__, pid); + if (fd != -1) { + if (tcsetpgrp(fd, pid) == -1) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO, + "%s: unable to set foreground pgrp to %d (editor)", + __func__, (int)pid); + } + close(fd); } } closefrom(STDERR_FILENO + 1);