From 893f539394fe34ee34f9aa404a4f8cce0a992866 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 8 Nov 2018 14:18:17 -0500 Subject: [PATCH] Fixes #55775 -- fixed regression in Command::exec's handling of PATH. This restores the previous behavior where if env_clear() or env_remove("PATH") was used we fall back to a default PATH of "/bin:/usr/bin" --- src/libstd/sys/unix/process/process_unix.rs | 5 +++-- src/test/run-pass/command-exec.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/process/process_unix.rs b/src/libstd/sys/unix/process/process_unix.rs index f41bd2c20720a..a5a93908b494d 100644 --- a/src/libstd/sys/unix/process/process_unix.rs +++ b/src/libstd/sys/unix/process/process_unix.rs @@ -135,14 +135,15 @@ impl Command { Some(envp) => { match envp.get_items().iter().find(|var| var.as_bytes().starts_with(b"PATH=")) { Some(p) => &p.as_bytes()[5..], - None => return None, + // Chosen to match what glibc does if there's no PATH variable + None => b"/bin:/usr/bin", } }, // maybe_envp is None if the process isn't changing the parent's env at all. None => { match parent_path.as_ref() { Some(p) => p.as_bytes(), - None => return None, + None => b"/bin:/usr/bin", } }, }; diff --git a/src/test/run-pass/command-exec.rs b/src/test/run-pass/command-exec.rs index 96f9da67790fc..0352161d7ddff 100644 --- a/src/test/run-pass/command-exec.rs +++ b/src/test/run-pass/command-exec.rs @@ -55,6 +55,16 @@ fn main() { println!("passed"); } + "exec-test6" => { + let err = Command::new("echo").arg("passed").env_clear().exec(); + panic!("failed to spawn: {}", err); + } + + "exec-test7" => { + let err = Command::new("echo").arg("passed").env_remove("PATH").exec(); + panic!("failed to spawn: {}", err); + } + _ => panic!("unknown argument: {}", arg), } return @@ -84,4 +94,14 @@ fn main() { assert!(output.status.success()); assert!(output.stderr.is_empty()); assert_eq!(output.stdout, b"passed\n"); + + let output = Command::new(&me).arg("exec-test6").output().unwrap(); + assert!(output.status.success()); + assert!(output.stderr.is_empty()); + assert_eq!(output.stdout, b"passed\n"); + + let output = Command::new(&me).arg("exec-test7").output().unwrap(); + assert!(output.status.success()); + assert!(output.stderr.is_empty()); + assert_eq!(output.stdout, b"passed\n"); }