From a42cf67acb3a30508178914235dffe252538ecfd Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 27 Mar 2018 16:00:08 -0600 Subject: [PATCH] In pty_close() we still need to check whether the pty master and slave fds are open before closing them. When no tty is present but we are I/O logging pty_close() will be called when there is no actual pty in use. --- src/exec_pty.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/exec_pty.c b/src/exec_pty.c index 396c3629c..7adb0a389 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -755,7 +755,8 @@ pty_close(struct command_status *cstat) debug_decl(pty_close, SUDO_DEBUG_EXEC); /* Close the pty slave first so reads from the master don't block. */ - close(io_fds[SFD_SLAVE]); + if (io_fds[SFD_SLAVE] != -1) + close(io_fds[SFD_SLAVE]); /* Flush any remaining output (the plugin already got it). */ if (io_fds[SFD_USERTTY] != -1) { @@ -786,7 +787,8 @@ pty_close(struct command_status *cstat) utmp_logout(slavename, cstat->type == CMD_WSTATUS ? cstat->val : 0); /* Close pty master. */ - close(io_fds[SFD_MASTER]); + if (io_fds[SFD_MASTER] != -1) + close(io_fds[SFD_MASTER]); debug_return; } -- 2.40.0