Skip to content

Commit 7f43921

Browse files
committed
security: Avoid using buggy atty crate
Switches to newer `is-terminal` crate instead. This functionality is also availible on the nightly Rust stdlib as a `std::io::IsTerminal` trait. Avoids RUSTSEC-2021-0145 (softprops/atty#50) Fixes slog-rs/slog#319 Based on the information in the vulnerability database, I don't consider this a particularly serious bug. > In practice however, the pointer won't be unaligned unless a custom global allocator is used.
1 parent 8c90668 commit 7f43921

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ nested-values = ["erased-serde", "serde", "serde_json", "slog/nested-values"]
2424

2525
[dependencies]
2626
slog = "2"
27-
atty = "0.2"
27+
is-terminal = "0.4"
2828
time = { version = "0.3", default-features = false, features = ["macros", "formatting"] }
2929
thread_local = "1"
3030
term = "0.7"

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ use std::io::Write as IoWrite;
9393
use std::panic::{RefUnwindSafe, UnwindSafe};
9494
use std::result;
9595
use std::{fmt, io, mem, sync};
96+
97+
// TODO: Should probably look into `std::io::IsTerminal` if/when that becomes stable
98+
// See tracking issue rust-lang/rust#98070
99+
//
100+
// This should really be an issue we file on the `is-terminal` crate
101+
use is_terminal::IsTerminal;
96102
// }}}
97103

98104
// {{{ Decorator
@@ -1332,8 +1338,8 @@ enum AnyTerminal {
13321338
impl AnyTerminal {
13331339
fn should_use_color(&self) -> bool {
13341340
match *self {
1335-
AnyTerminal::Stdout { .. } => atty::is(atty::Stream::Stdout),
1336-
AnyTerminal::Stderr { .. } => atty::is(atty::Stream::Stderr),
1341+
AnyTerminal::Stdout { .. } => std::io::stdout().is_terminal(),
1342+
AnyTerminal::Stderr { .. } => std::io::stderr().is_terminal(),
13371343
AnyTerminal::FallbackStdout => false,
13381344
AnyTerminal::FallbackStderr => false,
13391345
}

0 commit comments

Comments
 (0)