mirror of
https://github.com/rust-lang/cargo
synced 2024-10-05 23:39:47 +00:00
fix: Move off atty to resolve soundness issue
There is a soundness issue with atty when building on Windows with a custom allocator. This PR switches direct dependencies on atty to is-terminal. New semver compatible versions of clap and snapbox remove atty. #11417 upgrades env_logger to remove it from there. Fixes #11415
This commit is contained in:
parent
ee755e77da
commit
48895b1681
|
@ -16,7 +16,6 @@ name = "cargo"
|
|||
path = "src/cargo/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
atty = "0.2"
|
||||
bytesize = "1.0"
|
||||
cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" }
|
||||
cargo-util = { path = "crates/cargo-util", version = "0.2.3" }
|
||||
|
@ -37,6 +36,7 @@ http-auth = { version = "0.1.6", default-features = false }
|
|||
humantime = "2.0.0"
|
||||
indexmap = "1"
|
||||
ignore = "0.4.7"
|
||||
is-terminal = "0.4.0"
|
||||
lazy_static = "1.2.0"
|
||||
jobserver = "0.1.24"
|
||||
lazycell = "1.2.0"
|
||||
|
|
|
@ -9,4 +9,4 @@ cargo-util = { path = "../cargo-util" }
|
|||
proptest = "0.9.1"
|
||||
lazy_static = "1.3.0"
|
||||
varisat = "0.2.1"
|
||||
atty = "0.2.11"
|
||||
is-terminal = "0.4.0"
|
||||
|
|
|
@ -21,7 +21,7 @@ use proptest::prelude::*;
|
|||
proptest! {
|
||||
#![proptest_config(ProptestConfig {
|
||||
max_shrink_iters:
|
||||
if is_ci() || !atty::is(atty::Stream::Stderr) {
|
||||
if is_ci() || !is_terminal::IsTerminal::is_terminal(&std::io::stderr()){
|
||||
// This attempts to make sure that CI will fail fast,
|
||||
0
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::fmt;
|
||||
use std::io::prelude::*;
|
||||
|
||||
use is_terminal::IsTerminal;
|
||||
use termcolor::Color::{Cyan, Green, Red, Yellow};
|
||||
use termcolor::{self, Color, ColorSpec, StandardStream, WriteColor};
|
||||
|
||||
|
@ -99,14 +100,10 @@ impl Shell {
|
|||
let auto_clr = ColorChoice::CargoAuto;
|
||||
Shell {
|
||||
output: ShellOut::Stream {
|
||||
stdout: StandardStream::stdout(
|
||||
auto_clr.to_termcolor_color_choice(atty::Stream::Stdout),
|
||||
),
|
||||
stderr: StandardStream::stderr(
|
||||
auto_clr.to_termcolor_color_choice(atty::Stream::Stderr),
|
||||
),
|
||||
stdout: StandardStream::stdout(auto_clr.to_termcolor_color_choice(Stream::Stdout)),
|
||||
stderr: StandardStream::stderr(auto_clr.to_termcolor_color_choice(Stream::Stderr)),
|
||||
color_choice: ColorChoice::CargoAuto,
|
||||
stderr_tty: atty::is(atty::Stream::Stderr),
|
||||
stderr_tty: std::io::stderr().is_terminal(),
|
||||
},
|
||||
verbosity: Verbosity::Verbose,
|
||||
needs_clear: false,
|
||||
|
@ -301,8 +298,8 @@ impl Shell {
|
|||
),
|
||||
};
|
||||
*color_choice = cfg;
|
||||
*stdout = StandardStream::stdout(cfg.to_termcolor_color_choice(atty::Stream::Stdout));
|
||||
*stderr = StandardStream::stderr(cfg.to_termcolor_color_choice(atty::Stream::Stderr));
|
||||
*stdout = StandardStream::stdout(cfg.to_termcolor_color_choice(Stream::Stdout));
|
||||
*stderr = StandardStream::stderr(cfg.to_termcolor_color_choice(Stream::Stderr));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -496,12 +493,12 @@ impl ShellOut {
|
|||
|
||||
impl ColorChoice {
|
||||
/// Converts our color choice to termcolor's version.
|
||||
fn to_termcolor_color_choice(self, stream: atty::Stream) -> termcolor::ColorChoice {
|
||||
fn to_termcolor_color_choice(self, stream: Stream) -> termcolor::ColorChoice {
|
||||
match self {
|
||||
ColorChoice::Always => termcolor::ColorChoice::Always,
|
||||
ColorChoice::Never => termcolor::ColorChoice::Never,
|
||||
ColorChoice::CargoAuto => {
|
||||
if atty::is(stream) {
|
||||
if stream.is_terminal() {
|
||||
termcolor::ColorChoice::Auto
|
||||
} else {
|
||||
termcolor::ColorChoice::Never
|
||||
|
@ -511,6 +508,20 @@ impl ColorChoice {
|
|||
}
|
||||
}
|
||||
|
||||
enum Stream {
|
||||
Stdout,
|
||||
Stderr,
|
||||
}
|
||||
|
||||
impl Stream {
|
||||
fn is_terminal(self) -> bool {
|
||||
match self {
|
||||
Self::Stdout => std::io::stdout().is_terminal(),
|
||||
Self::Stderr => std::io::stderr().is_terminal(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
mod imp {
|
||||
use super::{Shell, TtyWidth};
|
||||
|
|
Loading…
Reference in a new issue