From 8fdbd56aad613b418efc20def9939d6e85d994a3 Mon Sep 17 00:00:00 2001 From: Kevin Ji <1146876+kevinji@users.noreply.github.com> Date: Wed, 28 Feb 2024 01:22:41 -0800 Subject: [PATCH] fix: replace atty with `std::io::IsTerminal` Resolves GHSA-g98v-hv3f-hcfr. --- Cargo.lock | 4 ---- Cargo.toml | 1 - crates/bin/pcli/Cargo.toml | 1 - crates/bin/pcli/src/command/init.rs | 7 +++++-- crates/bin/pcli/src/opt.rs | 3 ++- crates/bin/pclientd/Cargo.toml | 1 - crates/bin/pclientd/src/main.rs | 4 +++- crates/bin/pd/Cargo.toml | 1 - crates/bin/pd/src/main.rs | 3 ++- tools/summonerd/Cargo.toml | 1 - tools/summonerd/src/main.rs | 4 +++- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 298d2177c5..81fea3c7e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4404,7 +4404,6 @@ dependencies = [ "ark-ff", "assert_cmd", "async-stream", - "atty", "base64 0.21.7", "bincode", "blake2b_simd 1.0.2", @@ -4482,7 +4481,6 @@ dependencies = [ "assert_cmd", "async-stream", "async-trait", - "atty", "base64 0.21.7", "bytes", "camino", @@ -4535,7 +4533,6 @@ dependencies = [ "ark-ff", "async-stream", "async-trait", - "atty", "axum", "axum-server", "base64 0.21.7", @@ -7578,7 +7575,6 @@ dependencies = [ "ark-serialize", "askama", "async-trait", - "atty", "axum", "bytes", "camino", diff --git a/Cargo.toml b/Cargo.toml index d263f6a1fe..e9f9922b84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,7 +116,6 @@ ark-std = { default-features = false, version = "0.4" } assert_cmd = { version = "2.0" } async-stream = { version = "0.3.5" } async-trait = { version = "0.1.52" } -atty = { version = "0.2" } axum = { version = "0.6" } axum-server = { version = "0.4.7" } base64 = { version = "0.21.2" } diff --git a/crates/bin/pcli/Cargo.toml b/crates/bin/pcli/Cargo.toml index 863982d6c9..5e4d07b16c 100644 --- a/crates/bin/pcli/Cargo.toml +++ b/crates/bin/pcli/Cargo.toml @@ -33,7 +33,6 @@ parallel = [ anyhow = {workspace = true} ark-ff = {workspace = true, default-features = false} async-stream = {workspace = true} -atty = {workspace = true} base64 = {workspace = true} bincode = {workspace = true} blake2b_simd = {workspace = true} diff --git a/crates/bin/pcli/src/command/init.rs b/crates/bin/pcli/src/command/init.rs index 4af57486a4..f93655f070 100644 --- a/crates/bin/pcli/src/command/init.rs +++ b/crates/bin/pcli/src/command/init.rs @@ -1,4 +1,7 @@ -use std::{io::Read, str::FromStr}; +use std::{ + io::{IsTerminal as _, Read}, + str::FromStr, +}; use anyhow::Result; use camino::Utf8PathBuf; @@ -89,7 +92,7 @@ impl SoftKmsInitCmd { // The `rpassword` crate doesn't support reading from stdin, so we check // for an interactive session. We must support non-interactive use cases, // for integration with other tooling. - if atty::is(atty::Stream::Stdin) { + if std::io::stdin().is_terminal() { seed_phrase = rpassword::prompt_password("Enter seed phrase: ")?; } else { while let Ok(n_bytes) = std::io::stdin().lock().read_to_string(&mut seed_phrase) diff --git a/crates/bin/pcli/src/opt.rs b/crates/bin/pcli/src/opt.rs index 6f3cebb90f..5e29a7b689 100644 --- a/crates/bin/pcli/src/opt.rs +++ b/crates/bin/pcli/src/opt.rs @@ -16,6 +16,7 @@ use penumbra_proto::{ view::v1::{view_service_client::ViewServiceClient, view_service_server::ViewServiceServer}, }; use penumbra_view::ViewServer; +use std::io::IsTerminal as _; use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] @@ -31,7 +32,7 @@ pub struct Opt { impl Opt { pub fn init_tracing(&mut self) { tracing_subscriber::fmt() - .with_ansi(atty::is(atty::Stream::Stdout)) + .with_ansi(std::io::stdout().is_terminal()) .with_env_filter( EnvFilter::from_default_env() // Without explicitly disabling the `r1cs` target, the ZK proof implementations diff --git a/crates/bin/pclientd/Cargo.toml b/crates/bin/pclientd/Cargo.toml index a545f80d1b..ff7dfc4944 100644 --- a/crates/bin/pclientd/Cargo.toml +++ b/crates/bin/pclientd/Cargo.toml @@ -15,7 +15,6 @@ download-proving-keys = ["penumbra-proof-params/download-proving-keys"] anyhow = {workspace = true} async-stream = {workspace = true} async-trait = {workspace = true} -atty = {workspace = true} bytes = {workspace = true, features = ["serde"]} camino = {workspace = true} clap = {workspace = true, features = ["derive", "env"]} diff --git a/crates/bin/pclientd/src/main.rs b/crates/bin/pclientd/src/main.rs index 62825f0ae5..377028314a 100644 --- a/crates/bin/pclientd/src/main.rs +++ b/crates/bin/pclientd/src/main.rs @@ -1,4 +1,6 @@ #![deny(clippy::unwrap_used)] +use std::io::IsTerminal as _; + use anyhow::Result; use clap::Parser; use tracing_subscriber::{prelude::*, EnvFilter}; @@ -8,7 +10,7 @@ use pclientd::Opt; #[tokio::main] async fn main() -> Result<()> { let fmt_layer = tracing_subscriber::fmt::layer() - .with_ansi(atty::is(atty::Stream::Stdout)) + .with_ansi(std::io::stdout().is_terminal()) .with_target(true); let filter_layer = EnvFilter::try_from_default_env() .or_else(|_| EnvFilter::try_new("info"))? diff --git a/crates/bin/pd/Cargo.toml b/crates/bin/pd/Cargo.toml index 2ae072ec0d..7e2a0f2e95 100644 --- a/crates/bin/pd/Cargo.toml +++ b/crates/bin/pd/Cargo.toml @@ -124,7 +124,6 @@ console-subscriber = {workspace = true} metrics-tracing-context = {workspace = true} metrics-util = "0.16.2" clap = {workspace = true, features = ["derive", "env"]} -atty = {workspace = true} fs_extra = "1.3.0" axum-server = {workspace = true, features = ["tls-rustls"]} zip = "0.6" diff --git a/crates/bin/pd/src/main.rs b/crates/bin/pd/src/main.rs index b73a47f3b4..86bbfc2a40 100644 --- a/crates/bin/pd/src/main.rs +++ b/crates/bin/pd/src/main.rs @@ -2,6 +2,7 @@ #![deny(clippy::unwrap_used)] #![recursion_limit = "512"] use std::error::Error; +use std::io::IsTerminal as _; use console_subscriber::ConsoleLayer; use metrics_tracing_context::{MetricsLayer, TracingContextLayer}; @@ -46,7 +47,7 @@ async fn main() -> anyhow::Result<()> { let metrics_layer = MetricsLayer::new(); // The `FmtLayer` is used to print to the console. let fmt_layer = tracing_subscriber::fmt::layer() - .with_ansi(atty::is(atty::Stream::Stdout)) + .with_ansi(std::io::stdout().is_terminal()) .with_target(true); // The `EnvFilter` layer is used to filter events based on `RUST_LOG`. let filter_layer = EnvFilter::try_from_default_env().or_else(|_| EnvFilter::try_new("info"))?; diff --git a/tools/summonerd/Cargo.toml b/tools/summonerd/Cargo.toml index 3e81f4232d..4c34d38064 100644 --- a/tools/summonerd/Cargo.toml +++ b/tools/summonerd/Cargo.toml @@ -16,7 +16,6 @@ ark-groth16 = {workspace = true} ark-serialize = {workspace = true} askama = "0.11" async-trait = {workspace = true} -atty = {workspace = true} axum = {workspace = true} bytes = {workspace = true} camino = {workspace = true} diff --git a/tools/summonerd/src/main.rs b/tools/summonerd/src/main.rs index f45ff2295c..c72f60900e 100644 --- a/tools/summonerd/src/main.rs +++ b/tools/summonerd/src/main.rs @@ -27,8 +27,10 @@ use penumbra_proto::tools::summoning::v1::CeremonyCrs; use penumbra_proto::Message; use std::fs; use std::fs::File; +use std::io; use std::io::BufReader; use std::io::BufWriter; +use std::io::IsTerminal as _; use std::io::Read; use std::net::SocketAddr; use storage::Storage; @@ -358,7 +360,7 @@ async fn main() -> Result<()> { let console_layer = ConsoleLayer::builder().with_default_env().spawn(); // The `FmtLayer` is used to print to the console. let fmt_layer = tracing_subscriber::fmt::layer() - .with_ansi(atty::is(atty::Stream::Stdout)) + .with_ansi(io::stdout().is_terminal()) .with_target(true); // The `EnvFilter` layer is used to filter events based on `RUST_LOG`. let filter_layer = EnvFilter::try_from_default_env()