Skip to content

Commit

Permalink
More formatting + config for grouping imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasTNO committed Dec 9, 2024
1 parent 9a75a6a commit 71c1e6d
Show file tree
Hide file tree
Showing 32 changed files with 163 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Run `cargo fmt` to check formatting
- name: Check formatting with rustfmt
run: cargo fmt --all -- --check
run: cargo +nightly fmt --all -- --check

# Run `cargo clippy` for linting
- name: Run Clippy for linting
Expand Down
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Creates a Software Bill of Materials to be include in every build.
use cargo_license::{get_dependencies_from_cargo_lock, GetDependenciesOpt};
use std::{env, fs::File, io::Write, path::Path};

use cargo_license::{get_dependencies_from_cargo_lock, GetDependenciesOpt};

fn main() {
let dependencies = get_dependencies_from_cargo_lock(
Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
2 changes: 1 addition & 1 deletion src/authentication/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use openapiv3::OpenAPI;
use std::{borrow::Cow, fs::File, path::Path};

use anyhow::{Context, Result};
use cookie_store::{Cookie, RawCookie};
use openapiv3::OpenAPI;
use reqwest::header::{HeaderMap, IntoHeaderName, AUTHORIZATION};
use url::Url;

Expand Down
5 changes: 3 additions & 2 deletions src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use clap::{value_parser, Parser, Subcommand, ValueEnum};
use serde::Deserialize;
use std::{
convert::TryFrom,
io,
Expand All @@ -8,6 +6,9 @@ use std::{
path::{Path, PathBuf},
};

use clap::{value_parser, Parser, Subcommand, ValueEnum};
use serde::Deserialize;

const DEFAULT_REQUEST_TIMEOUT: u64 = 30000;
const DEFAULT_METHOD_MUTATION_STRATEGY: MethodMutationStrategy = MethodMutationStrategy::FollowSpec;
const DEFAULT_LOG_LEVEL: log::LevelFilter = log::LevelFilter::Info;
Expand Down
14 changes: 8 additions & 6 deletions src/coverage_clients/coverband.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//! Coverage client for agents that communicate using Coverband. Coverband can be used to
//! collect coverage on Ruby targets.
use super::CoverageClient;
use crate::coverage_clients::MAP_SIZE;
use reqwest::{
blocking::{Client, Response},
Url,
};
use std::{
collections::{hash_map::Entry, HashMap},
fmt::Debug,
path::Path,
};

use reqwest::{
blocking::{Client, Response},
Url,
};

use super::CoverageClient;
use crate::coverage_clients::MAP_SIZE;

#[derive(Debug, serde::Deserialize)]
struct CoverbandSegment {
filename: String,
Expand Down
9 changes: 5 additions & 4 deletions src/coverage_clients/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
//! attaching a coverage agent to a target is not always easy, and we do not support all types
//! of programming languages.
use super::{CoverageClient, MAP_SIZE};
use build_html::{escape_html, Container, ContainerType, Html, HtmlContainer, HtmlPage};
use indexmap::{map::Entry, IndexMap};
use openapiv3::{OpenAPI, StatusCode};
use std::{
convert::TryFrom,
fs::{create_dir_all, File},
Expand All @@ -21,6 +17,11 @@ use std::{
sync::{Arc, Mutex},
};

use build_html::{escape_html, Container, ContainerType, Html, HtmlContainer, HtmlPage};
use indexmap::{map::Entry, IndexMap};
use openapiv3::{OpenAPI, StatusCode};

use super::{CoverageClient, MAP_SIZE};
use crate::input::Method;

const HIT_SYMBOL: &str = "✔️";
Expand Down
6 changes: 3 additions & 3 deletions src/coverage_clients/jacoco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use std::{

extern crate num;

use libafl::Error;
use log::trace;

use crate::{
configuration::{Configuration, CoverageConfiguration},
coverage_clients::{
Expand All @@ -20,9 +23,6 @@ use crate::{
},
};

use libafl::Error;
use log::trace;

const REQUEST_HEADER: [u8; 5] = [0x01, 0xc0, 0xc0, 0x10, 0x07];
const BLOCK_CMD_DUMP: u8 = 0x40;
const JACOCO_HEADER: [u8; 2] = [0xc0, 0xc0];
Expand Down
5 changes: 3 additions & 2 deletions src/coverage_clients/lcov_client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Coverage client for agents that communicate using LCOV. This is a generic protocol,
//! and we can use it to get coverage from targets written in Python and Javascript.
use lcov::{Reader, Record};
use libafl::Error;
use std::{
cmp,
collections::HashMap,
Expand All @@ -13,6 +11,9 @@ use std::{
slice,
};

use lcov::{Reader, Record};
use libafl::Error;

use crate::{
configuration::{Configuration, CoverageConfiguration},
coverage_clients::{
Expand Down
73 changes: 36 additions & 37 deletions src/fuzzer.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
use anyhow::{Context, Result};

use libafl::{
corpus::Corpus,
events::EventFirer,
executors::{hooks::inprocess::inprocess_get_event_manager, Executor, HasObservers},
feedback_or,
feedbacks::{DifferentIsNovel, Feedback, MapFeedback, MaxReducer, TimeFeedback},
inputs::{BytesInput, UsesInput},
monitors::{AggregatorOps, UserStatsValue},
mutators::StdScheduledMutator,
observers::{CanTrack, ExplicitTracking, MultiMapObserver, TimeObserver},
schedulers::{
powersched::PowerSchedule, IndexesLenTimeMinimizerScheduler, PowerQueueScheduler,
},
stages::{CalibrationStage, StdPowerMutationalStage},
state::{HasCorpus, HasExecutions, NopState, UsesState},
ExecuteInputResult, ExecutionProcessor, HasNamedMetadata,
};

use libafl_bolts::{current_time, prelude::OwnedMutSlice, tuples::MatchName};
use openapiv3::OpenAPI;

use core::marker::PhantomData;
#[allow(unused_imports)]
use libafl::Fuzzer; // This may be marked unused, but will make the compiler give you crucial error messages
use libafl::{
corpus::OnDiskCorpus,
events::{Event, SimpleEventManager},
executors::{inprocess::InProcessExecutor, ExitKind},
feedbacks::{CrashFeedback, MaxMapFeedback},
fuzzer::StdFuzzer,
monitors::UserStats,
observers::StdMapObserver,
};
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list};
use std::{borrow::Cow, ops::DerefMut};

#[cfg(windows)]
use std::ptr::write_volatile;
use std::{
borrow::Cow,
fs::create_dir_all,
ops::DerefMut,
path::PathBuf,
sync::{
atomic::{AtomicBool, Ordering},
Expand All @@ -48,7 +13,41 @@ use std::{
time::{Duration, Instant},
};

use anyhow::{Context, Result};
#[allow(unused_imports)]
use libafl::Fuzzer; // This may be marked unused, but will make the compiler give you crucial error messages
use libafl::{
corpus::{Corpus, OnDiskCorpus},
events::{Event, EventFirer, SimpleEventManager},
executors::{
hooks::inprocess::inprocess_get_event_manager, inprocess::InProcessExecutor, Executor,
ExitKind, HasObservers,
},
feedback_or,
feedbacks::{
CrashFeedback, DifferentIsNovel, Feedback, MapFeedback, MaxMapFeedback, MaxReducer,
TimeFeedback,
},
fuzzer::StdFuzzer,
inputs::{BytesInput, UsesInput},
monitors::{AggregatorOps, UserStats, UserStatsValue},
mutators::StdScheduledMutator,
observers::{CanTrack, ExplicitTracking, MultiMapObserver, StdMapObserver, TimeObserver},
schedulers::{
powersched::PowerSchedule, IndexesLenTimeMinimizerScheduler, PowerQueueScheduler,
},
stages::{CalibrationStage, StdPowerMutationalStage},
state::{HasCorpus, HasExecutions, NopState, UsesState},
ExecuteInputResult, ExecutionProcessor, HasNamedMetadata,
};
use libafl_bolts::{
current_nanos, current_time,
prelude::OwnedMutSlice,
rands::StdRand,
tuples::{tuple_list, MatchName},
};
use log::{debug, error, info};
use openapiv3::OpenAPI;

use crate::{
configuration::{Configuration, CrashCriterion},
Expand Down
6 changes: 4 additions & 2 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
//! specify headers that should be sent with every request the fuzzer makes,
//! and this module parses those into a Reqwest HeaderMap.
use crate::configuration::Configuration;
use std::{collections::HashMap, fs::File, str::FromStr};

use anyhow::{Context, Result};
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use std::{collections::HashMap, fs::File, str::FromStr};

use crate::configuration::Configuration;

/// Load default headers from a file specified in configuration and apply
/// them to the given ClientBuilder
Expand Down
8 changes: 4 additions & 4 deletions src/initial_corpus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ use std::{
path::{Path, PathBuf},
};

use crate::{
initial_corpus::dependency_graph::initial_corpus_from_api,
input::{OpenApiInput, OpenApiRequest},
};
use libafl::{
corpus::{Corpus, InMemoryOnDiskCorpus, SchedulerTestcaseMetadata, Testcase},
HasMetadata,
};
use openapiv3::OpenAPI;

use self::dependency_graph::DependencyGraph;
use crate::{
initial_corpus::dependency_graph::initial_corpus_from_api,
input::{OpenApiInput, OpenApiRequest},
};

/// Loads an `OpenApiInput` from a yaml file.
pub fn load_starting_corpus(
Expand Down
26 changes: 14 additions & 12 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@
//! parameter_name: name_of_field_in_returned_object_from_first_request
//! ```
use self::parameter::ParameterKind;
pub use self::{method::Method, parameter::ParameterContents};
use crate::{
openapi::{find_operation, JsonContent, TextPlain, WwwForm},
parameter_feedback::ParameterFeedback,
state::HasRandAndOpenAPI,
use std::{
borrow::Cow,
fs::File,
hash::{BuildHasher, Hasher},
io::Read,
path::Path,
};

use ahash::RandomState;
use indexmap::{
map::{Iter, ValuesMut},
Expand All @@ -65,12 +66,13 @@ use indexmap::{
use libafl::{corpus::CorpusId, inputs::Input, Error};
use libafl_bolts::{fs::write_file_atomic, rands::Rand, HasLen};
use openapiv3::{OpenAPI, Operation, SchemaKind, Type};
use std::{
borrow::Cow,
fs::File,
hash::{BuildHasher, Hasher},
io::Read,
path::Path,

use self::parameter::ParameterKind;
pub use self::{method::Method, parameter::ParameterContents};
use crate::{
openapi::{find_operation, JsonContent, TextPlain, WwwForm},
parameter_feedback::ParameterFeedback,
state::HasRandAndOpenAPI,
};

pub mod method;
Expand Down
9 changes: 5 additions & 4 deletions src/input/parameter.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::{
borrow::Cow,
fmt::{Debug, Display, Formatter, Result},
};

use base64::{display::Base64Display, engine::general_purpose::STANDARD, Engine as _};
use indexmap::IndexMap;
use libafl_bolts::rands::Rand;
use openapiv3::Parameter;
use reqwest::header::HeaderValue;
use serde_json::{Map, Number, Value};
use std::{
borrow::Cow,
fmt::{Debug, Display, Formatter, Result},
};

use super::new_rand_input;

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ extern crate num_derive;
#[macro_use]
extern crate lazy_static;

#[allow(unused_imports)]
use libafl::Fuzzer; // This may be marked unused, but will make the compiler give you crucial error messages
#[cfg(windows)]
use std::ptr::write_volatile;
use std::sync::Arc;

use anyhow::Result;
use clap::Parser;
use configuration::{Commands, OutputFormat};
use env_logger::{Builder, Env};
#[allow(unused_imports)]
use libafl::Fuzzer; // This may be marked unused, but will make the compiler give you crucial error messages
use log::warn;
#[cfg(windows)]
use std::ptr::write_volatile;
use std::sync::Arc;

mod authentication;
mod configuration;
Expand Down
6 changes: 3 additions & 3 deletions src/monitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
//! while fuzzing, and tracks the time consumed.
use core::{time, time::Duration};

use crate::configuration::{Configuration, OutputFormat};
use std::{borrow::Cow, fmt};

use libafl::{
alloc::fmt::Debug,
monitors::{AggregatorOps, ClientStats, Monitor, UserStats, UserStatsValue},
};
use libafl_bolts::{current_time, format_duration_hms, ClientId};
use serde_json::json;
use std::{borrow::Cow, fmt};

use crate::configuration::{Configuration, OutputFormat};

/// Tracking monitor during fuzzing.
#[derive(Clone)]
Expand Down
3 changes: 2 additions & 1 deletion src/openapi/build_request.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::input::{parameter::ParameterKind, OpenApiRequest};
use cookie::Cookie;
use openapiv3::OpenAPI;
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};

use crate::input::{parameter::ParameterKind, OpenApiRequest};

/// Build a request to a path from the API using the input values.
pub fn build_request_from_input(
client: &reqwest::blocking::Client,
Expand Down
3 changes: 1 addition & 2 deletions src/openapi/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ use regex::Regex;
use serde_json::Value;
use unicode_truncate::UnicodeTruncateStr;

use super::{JsonContent, QualifiedOperation, WwwForm};
use crate::{
initial_corpus::dependency_graph::ParameterMatching,
input::{parameter::ParameterKind, Body, OpenApiInput, OpenApiRequest, ParameterContents},
};

use super::{JsonContent, QualifiedOperation, WwwForm};

/// Takes a (path, method, operation) tuple and produces an OpenApiRequest
/// filled with example values from the API specification, and default values
/// for parameters with no explicit examples.
Expand Down
Loading

0 comments on commit 71c1e6d

Please sign in to comment.