diff --git a/Cargo.lock b/Cargo.lock index f4e793220..101fe58f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,12 +36,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bitflags" version = "1.3.2" @@ -56,25 +50,23 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.22" +version = "4.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "30607dd93c420c6f1f80b544be522a0238a7db35e6a12968d28910983fee0df0" dependencies = [ "atty", "bitflags", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -136,12 +128,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hermit-abi" version = "0.1.19" @@ -151,16 +137,6 @@ dependencies = [ "libc", ] -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "instant" version = "0.1.12" @@ -296,12 +272,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" - [[package]] name = "thiserror" version = "1.0.33" diff --git a/Cargo.toml b/Cargo.toml index 91ac999c8..d9dc5168c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ tempfile = "3.3" xdg = "2.4" [dependencies] -clap = { version = "3.2", features = ["cargo"] } +clap = { version = "4.0", features = ["cargo"] } lazy_static = { version = "1.4.0", optional = true } libc = "0.2.134" rustc_version = "0.4" diff --git a/src/bin/cargo-afl.rs b/src/bin/cargo-afl.rs index 50ea6ec1d..4f66bbb89 100644 --- a/src/bin/cargo-afl.rs +++ b/src/bin/cargo-afl.rs @@ -1,7 +1,7 @@ use clap::crate_version; use std::env; -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::io; use std::process::{self, Command, ExitStatus, Stdio}; use std::sync::{Arc, Condvar, Mutex}; @@ -30,59 +30,55 @@ fn main() { match afl_matches.subcommand() { Some(("analyze", sub_matches)) => { let args = sub_matches - .values_of_os("afl-analyze args") + .get_many::("afl-analyze args") .unwrap_or_default(); run_afl(args, "afl-analyze", None); } Some(("cmin", sub_matches)) => { let args = sub_matches - .values_of_os("afl-cmin args") + .get_many::("afl-cmin args") .unwrap_or_default(); run_afl(args, "afl-cmin", None); } Some(("fuzz", sub_matches)) => { let args = sub_matches - .values_of_os("afl-fuzz args") + .get_many::("afl-fuzz args") .unwrap_or_default(); - let timeout = sub_matches.value_of("max_total_time").map(|_| { - sub_matches - .value_of_t::("max_total_time") - .unwrap_or_else(|e| e.exit()) - }); + let timeout = sub_matches.get_one::("max_total_time").copied(); run_afl(args, "afl-fuzz", timeout); } Some(("gotcpu", sub_matches)) => { let args = sub_matches - .values_of_os("afl-gotcpu args") + .get_many::("afl-gotcpu args") .unwrap_or_default(); run_afl(args, "afl-gotcpu", None); } Some(("plot", sub_matches)) => { let args = sub_matches - .values_of_os("afl-plot args") + .get_many::("afl-plot args") .unwrap_or_default(); run_afl(args, "afl-plot", None); } Some(("showmap", sub_matches)) => { let args = sub_matches - .values_of_os("afl-showmap args") + .get_many::("afl-showmap args") .unwrap_or_default(); run_afl(args, "afl-showmap", None); } Some(("tmin", sub_matches)) => { let args = sub_matches - .values_of_os("afl-tmin args") + .get_many::("afl-tmin args") .unwrap_or_default(); run_afl(args, "afl-tmin", None); } Some(("whatsup", sub_matches)) => { let args = sub_matches - .values_of_os("afl-whatsup args") + .get_many::("afl-whatsup args") .unwrap_or_default(); run_afl(args, "afl-whatsup", None); } Some((subcommand, sub_matches)) => { - let args = sub_matches.values_of_os("").unwrap_or_default(); + let args = sub_matches.get_many::("").unwrap_or_default(); run_cargo(subcommand, args); } // unreachable due to SubcommandRequiredElseHelp on "afl" subcommand @@ -91,138 +87,134 @@ fn main() { } #[allow(clippy::too_many_lines)] -fn clap_app() -> clap::App<'static> { - use clap::{ - App, - AppSettings::{ - AllowExternalSubcommands, AllowHyphenValues, AllowInvalidUtf8ForExternalSubcommands, - DisableHelpFlag, DisableHelpSubcommand, DisableVersionFlag, SubcommandRequiredElseHelp, - }, - Arg, - }; +fn clap_app() -> clap::Command { + use clap::{value_parser, Arg, Command}; - App::new("cargo afl") + Command::new("cargo afl") .bin_name("cargo") - .setting(SubcommandRequiredElseHelp) + .subcommand_required(true) + .arg_required_else_help(true) .subcommand( - App::new("afl") + Command::new("afl") .version(crate_version!()) - .setting(SubcommandRequiredElseHelp) - .setting(AllowExternalSubcommands) - .setting(AllowInvalidUtf8ForExternalSubcommands) + .subcommand_required(true) + .arg_required_else_help(true) + .allow_external_subcommands(true) + .external_subcommand_value_parser(value_parser!(OsString)) .override_usage("cargo afl [SUBCOMMAND or Cargo SUBCOMMAND]") .after_help( "In addition to the subcommands above, Cargo subcommands are also \ supported (see `cargo help` for a list of all Cargo subcommands).", ) .subcommand( - App::new("analyze") + Command::new("analyze") .about("Invoke afl-analyze") - .setting(AllowHyphenValues) - .setting(DisableHelpSubcommand) - .setting(DisableHelpFlag) - .setting(DisableVersionFlag) + .allow_hyphen_values(true) + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg( Arg::new("afl-analyze args") - .allow_invalid_utf8(true) - .multiple_values(true), + .value_parser(value_parser!(OsString)) + .num_args(0..), ), ) .subcommand( - App::new("cmin") + Command::new("cmin") .about("Invoke afl-cmin") - .setting(AllowHyphenValues) - .setting(DisableHelpSubcommand) - .setting(DisableHelpFlag) - .setting(DisableVersionFlag) + .allow_hyphen_values(true) + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg( Arg::new("afl-cmin args") - .allow_invalid_utf8(true) - .multiple_values(true), + .value_parser(value_parser!(OsString)) + .num_args(0..), ), ) .subcommand( - App::new("fuzz") + Command::new("fuzz") .about("Invoke afl-fuzz") - .setting(AllowHyphenValues) - .setting(DisableHelpSubcommand) - .setting(DisableHelpFlag) - .setting(DisableVersionFlag) + .allow_hyphen_values(true) + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg( Arg::new("max_total_time") .long("max_total_time") - .takes_value(true) + .num_args(1) + .value_parser(value_parser!(u64)) .help("Maximum amount of time to run the fuzzer"), ) .arg( Arg::new("afl-fuzz args") - .allow_invalid_utf8(true) - .multiple_values(true), + .value_parser(value_parser!(OsString)) + .num_args(0..), ), ) .subcommand( - App::new("gotcpu") + Command::new("gotcpu") .about("Invoke afl-gotcpu") - .setting(AllowHyphenValues) - .setting(DisableHelpSubcommand) - .setting(DisableHelpFlag) - .setting(DisableVersionFlag) + .allow_hyphen_values(true) + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg( Arg::new("afl-gotcpu args") - .allow_invalid_utf8(true) - .multiple_values(true), + .value_parser(value_parser!(OsString)) + .num_args(0..), ), ) .subcommand( - App::new("plot") + Command::new("plot") .about("Invoke afl-plot") - .setting(AllowHyphenValues) - .setting(DisableHelpSubcommand) - .setting(DisableHelpFlag) - .setting(DisableVersionFlag) + .allow_hyphen_values(true) + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg( Arg::new("afl-plot args") - .allow_invalid_utf8(true) - .multiple_values(true), + .value_parser(value_parser!(OsString)) + .num_args(0..), ), ) .subcommand( - App::new("showmap") + Command::new("showmap") .about("Invoke afl-showmap") - .setting(AllowHyphenValues) - .setting(DisableHelpSubcommand) - .setting(DisableHelpFlag) - .setting(DisableVersionFlag) + .allow_hyphen_values(true) + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg( Arg::new("afl-showmap args") - .allow_invalid_utf8(true) - .multiple_values(true), + .value_parser(value_parser!(OsString)) + .num_args(0..), ), ) .subcommand( - App::new("tmin") + Command::new("tmin") .about("Invoke afl-tmin") - .setting(AllowHyphenValues) - .setting(DisableHelpSubcommand) - .setting(DisableHelpFlag) - .setting(DisableVersionFlag) + .allow_hyphen_values(true) + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg( Arg::new("afl-tmin args") - .allow_invalid_utf8(true) - .multiple_values(true), + .value_parser(value_parser!(OsString)) + .num_args(0..), ), ) .subcommand( - App::new("whatsup") + Command::new("whatsup") .about("Invoke afl-whatsup") - .setting(AllowHyphenValues) - .setting(DisableHelpSubcommand) - .setting(DisableHelpFlag) - .setting(DisableVersionFlag) + .allow_hyphen_values(true) + .disable_help_subcommand(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg( Arg::new("afl-whatsup args") - .allow_invalid_utf8(true) - .multiple_values(true), + .value_parser(value_parser!(OsString)) + .num_args(0..), ), ), )