mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-26 22:51:53 +01:00
Fix for Windows: do not run binaries from CWD
This fixes a bug on Windows where `Command::new` would also run executables from the current working directory, possibly resulting in accidental runs of programs called `less`.
This commit is contained in:
parent
3617c98cf5
commit
bf2b2df9c9
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -1,5 +1,7 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "adler"
|
name = "adler"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@ -97,6 +99,7 @@ dependencies = [
|
|||||||
"error-chain",
|
"error-chain",
|
||||||
"git2",
|
"git2",
|
||||||
"globset",
|
"globset",
|
||||||
|
"grep-cli",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nix",
|
"nix",
|
||||||
"path_abs",
|
"path_abs",
|
||||||
@ -487,6 +490,23 @@ dependencies = [
|
|||||||
"regex",
|
"regex",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "grep-cli"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dd110c34bb4460d0de5062413b773e385cbf8a85a63fc535590110a09e79e8a"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"bstr",
|
||||||
|
"globset",
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
"same-file",
|
||||||
|
"termcolor",
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
@ -1143,6 +1163,15 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "terminal_size"
|
name = "terminal_size"
|
||||||
version = "0.1.16"
|
version = "0.1.16"
|
||||||
|
@ -51,6 +51,7 @@ path_abs = { version = "0.5", default-features = false }
|
|||||||
clircle = "0.3"
|
clircle = "0.3"
|
||||||
bugreport = "0.4"
|
bugreport = "0.4"
|
||||||
dirs-next = { version = "2.0.0", optional = true }
|
dirs-next = { version = "2.0.0", optional = true }
|
||||||
|
grep-cli = "0.1.6"
|
||||||
|
|
||||||
[dependencies.git2]
|
[dependencies.git2]
|
||||||
version = "0.13"
|
version = "0.13"
|
||||||
|
@ -4,7 +4,9 @@ use std::ffi::OsStr;
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<usize> {
|
pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<usize> {
|
||||||
let cmd = Command::new(less_path).arg("--version").output().ok()?;
|
let resolved_path = grep_cli::resolve_binary(less_path.as_ref()).ok()?;
|
||||||
|
|
||||||
|
let cmd = Command::new(resolved_path).arg("--version").output().ok()?;
|
||||||
parse_less_version(&cmd.stdout)
|
parse_less_version(&cmd.stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,14 @@ impl OutputType {
|
|||||||
return Err(ErrorKind::InvalidPagerValueBat.into());
|
return Err(ErrorKind::InvalidPagerValueBat.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut p = Command::new(&pager.bin);
|
let resolved_path = match grep_cli::resolve_binary(&pager.bin) {
|
||||||
|
Ok(path) => path,
|
||||||
|
Err(_) => {
|
||||||
|
return Ok(OutputType::stdout());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut p = Command::new(resolved_path);
|
||||||
let args = pager.args;
|
let args = pager.args;
|
||||||
|
|
||||||
if pager.kind == PagerKind::Less {
|
if pager.kind == PagerKind::Less {
|
||||||
|
Loading…
Reference in New Issue
Block a user