mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Restrict Nu with a cleaned environment. (#1222)
This commit is contained in:
committed by
GitHub
parent
98028433ad
commit
78a644da2b
@ -226,10 +226,12 @@ pub fn executable_path() -> PathBuf {
|
||||
}
|
||||
|
||||
pub fn binaries() -> PathBuf {
|
||||
let mut path = PathBuf::new();
|
||||
path.push("target");
|
||||
path.push("debug");
|
||||
path
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.expect("Couldn't find the debug binaries directory")
|
||||
.parent()
|
||||
.expect("Couldn't find the debug binaries directory")
|
||||
.join("target/debug")
|
||||
}
|
||||
|
||||
pub fn in_directory(str: impl AsRef<Path>) -> String {
|
||||
|
@ -28,7 +28,18 @@ macro_rules! nu {
|
||||
$crate::fs::DisplayPath::display_path(&$path)
|
||||
);
|
||||
|
||||
let dummies = $crate::fs::binaries();
|
||||
let dummies = dunce::canonicalize(&dummies).unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Couldn't canonicalize dummy binaries path {}: {:?}",
|
||||
dummies.display(),
|
||||
e
|
||||
)
|
||||
});
|
||||
|
||||
let mut process = match Command::new($crate::fs::executable_path())
|
||||
.env_clear()
|
||||
.env("PATH", dummies)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
@ -85,7 +96,18 @@ macro_rules! nu_error {
|
||||
$crate::fs::DisplayPath::display_path(&$path)
|
||||
);
|
||||
|
||||
let dummies = $crate::fs::binaries();
|
||||
let dummies = dunce::canonicalize(&dummies).unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Couldn't canonicalize dummy binaries path {}: {:?}",
|
||||
dummies.display(),
|
||||
e
|
||||
)
|
||||
});
|
||||
|
||||
let mut process = Command::new($crate::fs::executable_path())
|
||||
.env_clear()
|
||||
.env("PATH", dummies)
|
||||
.stdout(Stdio::piped())
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
|
Reference in New Issue
Block a user