Skip to content

Commit

Permalink
fix: replace atty with std::io::IsTerminal (#3907)
Browse files Browse the repository at this point in the history
Resolves GHSA-g98v-hv3f-hcfr.

`std::io::IsTerminal` has been present since [Rust
1.70](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html).
  • Loading branch information
kevinji authored Mar 1, 2024
1 parent 553b344 commit f410d39
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 15 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 0 additions & 1 deletion crates/bin/pcli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 5 additions & 2 deletions crates/bin/pcli/src/command/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{io::Read, str::FromStr};
use std::{
io::{IsTerminal as _, Read},
str::FromStr,
};

use anyhow::Result;
use camino::Utf8PathBuf;
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion crates/bin/pcli/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion crates/bin/pclientd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand Down
4 changes: 3 additions & 1 deletion crates/bin/pclientd/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![deny(clippy::unwrap_used)]
use std::io::IsTerminal as _;

use anyhow::Result;
use clap::Parser;
use tracing_subscriber::{prelude::*, EnvFilter};
Expand All @@ -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"))?
Expand Down
1 change: 0 additions & 1 deletion crates/bin/pd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion crates/bin/pd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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"))?;
Expand Down
1 change: 0 additions & 1 deletion tools/summonerd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion tools/summonerd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f410d39

Please sign in to comment.