Skip to content

Commit f5a4d16

Browse files
committed
Fix bug where the parent handlers were leaked to the moniton
1 parent 3418eb3 commit f5a4d16

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

sudo/lib/exec/event.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,11 @@ impl<T: EventClosure> EventDispatcher<T> {
200200
}
201201
}
202202
}
203+
204+
/// Unregister all the handlers created by the dispatcher.
205+
pub(super) fn unregister_handlers(self) {
206+
for handler in self.signal_handlers {
207+
handler.unregister();
208+
}
209+
}
203210
}

sudo/lib/exec/parent.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub(super) fn exec_pty(
5454
// enabled or if sudo is running in background.
5555
// FIXME (ogsudo): Copy terminal settings from `/dev/tty` to the pty.
5656
// FIXME (ogsudo): Start in raw mode unless we're part of a pipeline
57+
// FIXME: it would be better if we didn't create the dispatcher before the fork and managed
58+
// to block all the signals instead.
5759
let mut dispatcher = EventDispatcher::<ParentClosure>::new()?;
5860

5961
let monitor_pid = fork().map_err(|err| {
@@ -66,6 +68,10 @@ pub(super) fn exec_pty(
6668
drop(pty.leader);
6769
drop(backchannels.parent);
6870

71+
// Unregister all the handlers so `exec_monitor` can register new ones for the monitor
72+
// process.
73+
dispatcher.unregister_handlers();
74+
6975
// If `exec_monitor` returns, it means we failed to execute the command somehow.
7076
if let Err(err) = exec_monitor(pty.follower, command, &mut backchannels.monitor) {
7177
if let Err(err) = backchannels.monitor.send(&err.into()) {

0 commit comments

Comments
 (0)