summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <Todd.Miller@sudo.ws>2023-03-24 11:01:58 -0600
committerTodd C. Miller <Todd.Miller@sudo.ws>2023-03-24 11:01:58 -0600
commit9020370f167cc97fcc237cc75cc0b70fb90df25f (patch)
tree73986cb3f54ca69dd87ab863b60276c0dbea71f3
parentd0cc84bc556de6758380281879e074c43ca2bd7c (diff)
downloadsudo-9020370f167cc97fcc237cc75cc0b70fb90df25f.tar.gz
Register pty cleanup function in exec_pty(), not exec_cmnd_pty().
We want it to execute in the main sudo process, not the monitor.
-rw-r--r--src/exec_monitor.c5
-rw-r--r--src/exec_pty.c9
-rw-r--r--src/sudo_exec.h1
3 files changed, 9 insertions, 6 deletions
diff --git a/src/exec_monitor.c b/src/exec_monitor.c
index eacc0079e..f18b612c7 100644
--- a/src/exec_monitor.c
+++ b/src/exec_monitor.c
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
- * Copyright (c) 2009-2022 Todd C. Miller <Todd.Miller@sudo.ws>
+ * Copyright (c) 2009-2023 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -354,9 +354,6 @@ exec_cmnd_pty(struct command_details *details, sigset_t *mask,
volatile pid_t self = getpid();
debug_decl(exec_cmnd_pty, SUDO_DEBUG_EXEC);
- /* Register cleanup function */
- sudo_fatal_callback_register(pty_cleanup);
-
/* Set command process group here too to avoid a race. */
setpgid(0, self);
diff --git a/src/exec_pty.c b/src/exec_pty.c
index 22601201d..5a366062b 100644
--- a/src/exec_pty.c
+++ b/src/exec_pty.c
@@ -67,7 +67,7 @@ static void schedule_signal(struct exec_closure *ec, int signo);
/*
* Cleanup hook for sudo_fatal()/sudo_fatalx()
*/
-void
+static void
pty_cleanup(void)
{
debug_decl(cleanup, SUDO_DEBUG_EXEC);
@@ -1075,6 +1075,9 @@ exec_pty(struct command_details *details, struct command_status *cstat)
if (!pty_setup(details, user_details.tty))
debug_return_bool(false);
+ /* Register cleanup function */
+ sudo_fatal_callback_register(pty_cleanup);
+
/*
* We communicate with the monitor over a bi-directional pair of sockets.
* Parent sends signal info to monitor and monitor sends back wait status.
@@ -1284,6 +1287,10 @@ exec_pty(struct command_details *details, struct command_status *cstat)
close(io_pipe[STDOUT_FILENO][0]);
if (io_pipe[STDERR_FILENO][0] != -1)
close(io_pipe[STDERR_FILENO][0]);
+
+ /* Only run the cleanup hook in the parent. */
+ sudo_fatal_callback_deregister(pty_cleanup);
+
/*
* If stdin/stdout is not a tty, start command in the background
* since it might be part of a pipeline that reads from /dev/tty.
diff --git a/src/sudo_exec.h b/src/sudo_exec.h
index 57ada3de8..4b7b23f06 100644
--- a/src/sudo_exec.h
+++ b/src/sudo_exec.h
@@ -212,7 +212,6 @@ void exec_nopty(struct command_details *details, struct command_status *cstat);
/* exec_pty.c */
bool exec_pty(struct command_details *details, struct command_status *cstat);
-void pty_cleanup(void);
int pty_make_controlling(void);
extern int io_fds[6];