Deny direct process spawn methods in Clippy

This commit is contained in:
Adam Perry
2026-05-21 14:52:18 -07:00
parent 4acb456bfe
commit a4abf76e8d
35 changed files with 47 additions and 0 deletions
+1
View File
@@ -95,6 +95,7 @@ build:clippy --@rules_rust//rust/settings:clippy.toml=//codex-rs:clippy.toml
build:clippy --@rules_rust//rust/settings:clippy_flag=-Dwarnings
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::await_holding_invalid_type
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::await_holding_lock
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::disallowed_methods
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::expect_used
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::identity_op
build:clippy --@rules_rust//rust/settings:clippy_flag=--deny=clippy::manual_clamp
+1
View File
@@ -433,6 +433,7 @@ rust = {}
[workspace.lints.clippy]
await_holding_invalid_type = "deny"
await_holding_lock = "deny"
disallowed_methods = "deny"
expect_used = "deny"
identity_op = "deny"
manual_clamp = "deny"
@@ -177,6 +177,7 @@ impl PidBackend {
}
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let child = match command.spawn() {
Ok(child) => child,
Err(err) => {
@@ -164,6 +164,7 @@ async fn install_latest_standalone() -> Result<()> {
.await
.context("failed to read standalone Codex updater")?;
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = Command::new("/bin/sh")
.arg("-s")
.stdin(Stdio::piped())
@@ -482,6 +482,7 @@ impl BackgroundAppServer {
for override_kv in config_overrides {
cmd.arg("--config").arg(override_kv);
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let process = cmd
.arg("app-server")
.arg("--listen")
@@ -535,6 +536,7 @@ fn serve(codex_bin: &Path, config_overrides: &[String], listen: &str, kill: bool
}
cmdline.push_str(&format!(" app-server --listen {}", shell_quote(listen)));
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let child = Command::new("nohup")
.arg("sh")
.arg("-c")
@@ -1444,6 +1446,7 @@ impl CodexClient {
for override_kv in config_overrides {
cmd.arg("--config").arg(override_kv);
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut codex_app_server = cmd
.arg("app-server")
.stdin(Stdio::piped())
@@ -206,6 +206,7 @@ impl McpProcess {
}
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut process = cmd
.kill_on_drop(true)
.spawn()
@@ -396,6 +396,7 @@ pub(super) async fn spawn_websocket_server_with_args(
.stderr(Stdio::piped())
.env("CODEX_HOME", codex_home)
.env("RUST_LOG", "warn");
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut process = cmd
.kill_on_drop(true)
.spawn()
+1
View File
@@ -491,6 +491,7 @@ async fn spawn_debug_sandbox_child(
cmd.env(CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR, "1");
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
cmd.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
@@ -290,6 +290,7 @@ mod tests {
#[cfg(target_os = "macos")]
#[test]
fn list_child_pids_includes_spawned_child() {
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = Command::new("/bin/sleep")
.arg("5")
.stdin(Stdio::null())
@@ -319,6 +320,7 @@ mod tests {
async fn pid_tracker_collects_spawned_children() {
let tracker = PidTracker::new(std::process::id() as i32).expect("failed to create tracker");
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = Command::new("/bin/sleep")
.arg("0.1")
.stdin(Stdio::null())
@@ -347,6 +349,7 @@ mod tests {
async fn pid_tracker_collects_bash_subshell_descendants() {
let tracker = PidTracker::new(std::process::id() as i32).expect("failed to create tracker");
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let child = Command::new("/bin/bash")
.arg("-c")
.arg("(sleep 0.1 & echo $!; wait)")
@@ -89,6 +89,7 @@ fn start_log_stream() -> Option<Child> {
const PREDICATE: &str = r#"(((processID == 0) AND (senderImagePath CONTAINS "/Sandbox")) OR (subsystem == "com.apple.sandbox.reporting"))"#;
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
tokio::process::Command::new("log")
.args(["stream", "--style", "ndjson", "--predicate", PREDICATE])
.stdin(Stdio::null())
+3
View File
@@ -6,6 +6,9 @@ await-holding-invalid-types = [
"tokio::sync::RwLockWriteGuard",
]
disallowed-methods = [
{ path = "std::process::Command::spawn", reason = "Don't leak processes on Drop." },
{ path = "tokio::process::Command::spawn", reason = "Don't leak processes on Drop." },
{ path = "portable_pty::SlavePty::spawn_command", reason = "Don't leak processes on Drop." },
{ path = "ratatui::style::Color::Rgb", reason = "Use ANSI colors, which work better in various terminal themes." },
{ path = "ratatui::style::Color::Indexed", reason = "Use ANSI colors, which work better in various terminal themes." },
{ path = "ratatui::style::Stylize::white", reason = "Avoid hardcoding white; prefer default fg or dim/bold. Exception: Disable this rule if rendering over a hardcoded ANSI background." },
@@ -168,6 +168,7 @@ fn run_git_command_with_timeout(
context: &str,
timeout: Duration,
) -> Result<Output, String> {
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = command
.stdin(Stdio::null())
.stdout(Stdio::piped())
@@ -523,6 +523,7 @@ fn run_git_command_with_timeout(
context: &str,
timeout: Duration,
) -> Result<Output, String> {
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = command
.stdin(Stdio::null())
.stdout(Stdio::piped())
+1
View File
@@ -122,5 +122,6 @@ pub(crate) async fn spawn_child_async(request: SpawnChildRequest<'_>) -> std::io
}
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
cmd.kill_on_drop(true).spawn()
}
+1
View File
@@ -60,6 +60,7 @@ fn run_live(prompt: &str) -> (assert_cmd::assert::Assert, TempDir) {
cmd.stdout(Stdio::piped());
cmd.stderr(Stdio::piped());
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = cmd.spawn().expect("failed to spawn codex-rs");
// Send the terminating newline so Session::run exits after the first turn.
+1
View File
@@ -2099,6 +2099,7 @@ async fn start_streamable_http_test_server(
if let Some(expected_token) = expected_token {
command.env("MCP_EXPECT_BEARER", expected_token);
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = command.spawn()?;
wait_for_local_streamable_http_server(&mut child, &server_url, Duration::from_secs(5)).await?;
+1
View File
@@ -63,6 +63,7 @@ impl AppServerClient {
cmd.arg("--config").arg(override_kv);
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = cmd
.arg("app-server")
.stdin(Stdio::piped())
@@ -82,6 +82,7 @@ impl ExecServerClient {
pub(crate) async fn connect_stdio_command(
args: StdioExecServerConnectArgs,
) -> Result<Self, ExecServerError> {
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = stdio_command_process(&args.command)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
+1
View File
@@ -298,6 +298,7 @@ fn spawn_command(
command.stdin(std::process::Stdio::piped());
command.stdout(std::process::Stdio::piped());
command.stderr(std::process::Stdio::piped());
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
command.spawn().map_err(io_error)
}
@@ -76,6 +76,7 @@ where
child.kill_on_drop(true);
child.env("CODEX_HOME", codex_home.path());
child.envs(env);
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = child.spawn()?;
let websocket_url = read_listen_url_from_stdout(&mut child).await?;
+1
View File
@@ -89,6 +89,7 @@ fn run_delayed_output_after_exit_parent(release_path: &Path) {
std::process::exit(1);
}
};
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
match Command::new(current_exe)
.arg(DELAYED_OUTPUT_AFTER_EXIT_CHILD_ARG)
.arg(release_path)
+1
View File
@@ -76,6 +76,7 @@ async fn spawn_command_under_sandbox(
}
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
child.kill_on_drop(true).spawn()
}
@@ -38,6 +38,7 @@ pub(crate) async fn run_command(
.stderr(Stdio::piped())
.kill_on_drop(true);
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = match command.spawn() {
Ok(child) => child,
Err(err) => {
+1
View File
@@ -60,6 +60,7 @@ pub fn notify_hook(argv: Vec<String>) -> Hook {
.stdout(Stdio::null())
.stderr(Stdio::null());
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
match command.spawn() {
Ok(_) => HookResult::Success,
Err(err) => HookResult::FailedContinue(err.into()),
@@ -78,6 +78,7 @@ impl McpProcess {
}
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut process = cmd
.kill_on_drop(true)
.spawn()
@@ -199,6 +199,7 @@ pub(crate) async fn spawn_streamable_http_server() -> anyhow::Result<(Child, Str
let bind_addr = format!("127.0.0.1:{port}");
let base_url = format!("http://{bind_addr}");
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = Command::new(streamable_http_server_bin()?)
.kill_on_drop(true)
.env("MCP_STREAMABLE_HTTP_BIND_ADDR", &bind_addr)
@@ -225,6 +226,7 @@ impl Drop for ExecServerProcess {
/// Starts a local exec-server and connects an initialized `ExecServerClient`.
pub(crate) async fn spawn_exec_server() -> anyhow::Result<ExecServerProcess> {
let codex_home = TempDir::new()?;
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = Command::new(codex_utils_cargo_bin::cargo_bin("codex")?)
.args(["exec-server", "--listen", "ws://127.0.0.1:0"])
.stdin(Stdio::null())
+1
View File
@@ -72,6 +72,7 @@ fn system_bwrap_warning_for_path(system_bwrap_path: Option<&Path>) -> Option<Str
}
fn system_bwrap_has_user_namespace_access(system_bwrap_path: &Path, timeout: Duration) -> bool {
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = match Command::new(system_bwrap_path)
.args([
"--unshare-user",
@@ -113,6 +113,7 @@ struct PowershellParserProcess {
impl PowershellParserProcess {
fn spawn(executable: &str) -> std::io::Result<Self> {
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = Command::new(executable)
.args([
"-NoLogo",
@@ -345,6 +345,7 @@ async fn handle_escalate_session_with_policy(
Ok(())
});
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = command.spawn()?;
let exit_status = tokio::select! {
status = child.wait() => status?,
@@ -72,6 +72,7 @@ async fn pipes_stdin_and_stdout_through_socket() -> anyhow::Result<()> {
let child_task = tokio::task::spawn_blocking(move || -> anyhow::Result<ChildOutput> {
let stdin =
std::fs::File::open(&request_path).context("failed to open child stdin fixture")?;
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = Command::new(codex_utils_cargo_bin::cargo_bin("codex-stdio-to-uds")?)
.arg(&socket_path)
.stdin(Stdio::from(stdin))
+5
View File
@@ -262,6 +262,10 @@ fn arboard_copy(_text: &str) -> Result<Option<ClipboardLease>, String> {
/// Copy text into the Windows clipboard from a WSL process.
#[cfg(target_os = "linux")]
fn wsl_clipboard_copy(text: &str) -> Result<(), String> {
#[allow(
clippy::disallowed_methods,
reason = "Grandfathered-in usage."
)]
let mut child = std::process::Command::new("powershell.exe")
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::null())
@@ -321,6 +325,7 @@ fn tmux_clipboard_copy(text: &str) -> Result<(), String> {
|| tmux_command_output(["info"]),
)?;
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = std::process::Command::new("tmux")
.args(["load-buffer", "-w", "-"])
.stdin(std::process::Stdio::piped())
+1
View File
@@ -147,6 +147,7 @@ async fn spawn_process_with_stdin_mode(
command.stdout(Stdio::piped());
command.stderr(Stdio::piped());
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = command.spawn()?;
let pid = child
.id()
+2
View File
@@ -158,6 +158,7 @@ async fn spawn_process_portable(
command_builder.env(key, value);
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = pair.slave.spawn_command(command_builder)?;
#[cfg(unix)]
// portable-pty establishes the spawned PTY child as a new session leader on
@@ -322,6 +323,7 @@ async fn spawn_process_preserving_fds(
});
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
let mut child = command.spawn()?;
drop(slave);
let process_group_id = child.id();
@@ -222,6 +222,7 @@ fn spawn_backend(backend: LinuxBackend) -> Result<Child, std::io::Error> {
});
}
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
command.spawn()
}
@@ -163,6 +163,7 @@ fn spawn_read_acl_helper(payload: &Payload, _log: &mut File) -> Result<()> {
let payload_json = serde_json::to_vec(&read_payload)?;
let payload_b64 = BASE64.encode(payload_json);
let exe = std::env::current_exe().context("locate setup helper")?;
#[allow(clippy::disallowed_methods, reason = "Grandfathered-in usage.")]
Command::new(&exe)
.arg(payload_b64)
.stdin(Stdio::null())