From fb208d383af27a07abe9cb277a620ea34c73f5d7 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 14 Jul 2025 16:55:34 -0600 Subject: [PATCH] revoke_pty: use killpg() not kill() to send HUP to the process group Also make sure we never call killpg(-1, SIGHUP), which would send SIGHUP to process 1 (init). It is possible for cmnd_pid to be -1 in certain error conditions where sudo killed the command itself. This may explain GitHub issue #458. --- src/exec_pty.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/exec_pty.c b/src/exec_pty.c index fb384d13c..0789305ec 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -358,9 +358,11 @@ revoke_pty(struct exec_closure *ec) pgrp = tcpgrp; close(io_fds[SFD_LEADER]); } - sudo_debug_printf(SUDO_DEBUG_NOTICE, "%s: killpg(%d, SIGHUP)", - __func__, (int)pgrp); - kill(pgrp, SIGHUP); + if (pgrp != -1) { + sudo_debug_printf(SUDO_DEBUG_NOTICE, "%s: killpg(%d, SIGHUP)", + __func__, (int)pgrp); + killpg(pgrp, SIGHUP); + } } /*