Skip to content

Commit e226d20

Browse files
authored
Fix a panic when exec fails with use_pty enabled (#1298)
2 parents 2ade7d5 + eeb1ad7 commit e226d20

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/exec/use_pty/monitor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,7 @@ impl<'a> MonitorClosure<'a> {
298298
Err(err) => registry.set_break(err),
299299
Ok(error_code) => {
300300
// Received error code from the command, forward it to the parent.
301-
self.backchannel
302-
.send(&ParentMessage::IoError(error_code))
303-
.ok();
301+
registry.set_break(io::Error::from_raw_os_error(error_code));
304302
}
305303
}
306304
}

test-framework/sudo-compliance-tests/src/sudo/misc.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use sudo_test::User;
2-
use sudo_test::{helpers::assert_ls_output, Command, Env, BIN_SUDO};
1+
use sudo_test::{helpers::assert_ls_output, is_original_sudo, Command, Env, User, BIN_SUDO};
32

43
use crate::{Result, PANIC_EXIT_CODE, SUDOERS_ALL_ALL_NOPASSWD, USERNAME};
54

@@ -202,6 +201,25 @@ fn does_not_panic_on_io_errors_cli_error() -> Result<()> {
202201
Ok(())
203202
}
204203

204+
#[test]
205+
fn does_not_panic_on_invalid_executable() {
206+
let env = Env(SUDOERS_ALL_ALL_NOPASSWD).build();
207+
208+
let output = Command::new("bash")
209+
.args(["-c", "sudo /tmp; a=$?; sleep .1; exit $a"])
210+
.tty(true) // Necessary to reproduce the panic
211+
.output(&env);
212+
output.assert_exit_code(1);
213+
214+
assert!(!output.stderr().contains("panic"), "{output:?}");
215+
assert!(!output.stdout_unchecked().contains("panic"), "{output:?}");
216+
if is_original_sudo() {
217+
assert_contains!(output.stdout_unchecked(), "command not found");
218+
} else {
219+
assert_contains!(output.stdout_unchecked(), "Permission denied");
220+
}
221+
}
222+
205223
#[test]
206224
#[cfg_attr(
207225
target_os = "freebsd",

0 commit comments

Comments
 (0)