Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasTNO committed Dec 9, 2024
1 parent 481529a commit 9a75a6a
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 121 deletions.
5 changes: 1 addition & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Creates a Software Bill of Materials to be include in every build.
use cargo_license::{get_dependencies_from_cargo_lock, GetDependenciesOpt};
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::{env, fs::File, io::Write, path::Path};

fn main() {
let dependencies = get_dependencies_from_cargo_lock(
Expand Down
11 changes: 7 additions & 4 deletions src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use clap::{value_parser, Parser, Subcommand, ValueEnum};
use serde::Deserialize;
use std::convert::TryFrom;
use std::io::ErrorKind;
use std::net::ToSocketAddrs;
use std::{io, net::SocketAddr, path::Path, path::PathBuf};
use std::{
convert::TryFrom,
io,
io::ErrorKind,
net::{SocketAddr, ToSocketAddrs},
path::{Path, PathBuf},
};

const DEFAULT_REQUEST_TIMEOUT: u64 = 30000;
const DEFAULT_METHOD_MUTATION_STRATEGY: MethodMutationStrategy = MethodMutationStrategy::FollowSpec;
Expand Down
8 changes: 5 additions & 3 deletions src/coverage_clients/coverband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
use super::CoverageClient;
use crate::coverage_clients::MAP_SIZE;
use reqwest::blocking::{Client, Response};
use reqwest::Url;
use std::path::Path;
use reqwest::{
blocking::{Client, Response},
Url,
};
use std::{
collections::{hash_map::Entry, HashMap},
fmt::Debug,
path::Path,
};

#[derive(Debug, serde::Deserialize)]
Expand Down
24 changes: 15 additions & 9 deletions src/coverage_clients/jacoco.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
//! Coverage client for agents that communicate using Jacoco. Jacoco is the supported way
//! to collect coverage from Java targets.
use std::collections::{hash_map::Entry, HashMap};
use std::fs::{create_dir_all, read_dir, remove_file, DirBuilder, OpenOptions};
use std::io::prelude::*;
use std::net::{SocketAddr, TcpStream};
use std::path::{Path, PathBuf};
use std::slice;
use std::{
collections::{hash_map::Entry, HashMap},
fs::{create_dir_all, read_dir, remove_file, DirBuilder, OpenOptions},
io::prelude::*,
net::{SocketAddr, TcpStream},
path::{Path, PathBuf},
slice,
};

extern crate num;

use crate::configuration::{Configuration, CoverageConfiguration};
use crate::coverage_clients::read_utilities::{read_bool_array, read_cesu8, read_char, read_u64be};
use crate::coverage_clients::{CoverageClient, MAP_SIZE};
use crate::{
configuration::{Configuration, CoverageConfiguration},
coverage_clients::{
read_utilities::{read_bool_array, read_cesu8, read_char, read_u64be},
CoverageClient, MAP_SIZE,
},
};

use libafl::Error;
use log::trace;
Expand Down
19 changes: 11 additions & 8 deletions src/coverage_clients/lcov_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
use lcov::{Reader, Record};
use libafl::Error;
use std::fs::{create_dir_all, read_dir, File};
use std::io::prelude::*;
use std::net::{SocketAddr, TcpStream};
use std::{cmp, slice};
use std::{
cmp,
collections::HashMap,
fs::{create_dir_all, read_dir, File},
io::prelude::*,
net::{SocketAddr, TcpStream},
path::{Path, PathBuf},
slice,
};

use crate::configuration::{Configuration, CoverageConfiguration};
use crate::coverage_clients::{
read_utilities::{read_byte_vec, read_char},
CoverageClient, MAP_SIZE,
use crate::{
configuration::{Configuration, CoverageConfiguration},
coverage_clients::{
read_utilities::{read_byte_vec, read_char},
CoverageClient, MAP_SIZE,
},
};
extern crate num;

Expand Down
7 changes: 4 additions & 3 deletions src/coverage_clients/read_utilities.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Collection of utility functions to read data from a stream.
use std::convert::{TryFrom, TryInto};
use std::io::ErrorKind;
use std::io::{prelude::*, Error, Result};
use std::{
convert::{TryFrom, TryInto},
io::{prelude::*, Error, ErrorKind, Result},
};

use byteorder::{BigEndian, ByteOrder, LittleEndian};
use cesu8::{from_java_cesu8, to_java_cesu8};
Expand Down
57 changes: 29 additions & 28 deletions src/fuzzer.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
use anyhow::{Context, Result};

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

use libafl_bolts::current_time;
use libafl_bolts::prelude::OwnedMutSlice;
use libafl_bolts::tuples::MatchName;

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

use core::marker::PhantomData;
Expand All @@ -35,23 +34,25 @@ use libafl::{
observers::StdMapObserver,
};
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list};
use std::borrow::Cow;
use std::ops::DerefMut;
use std::{borrow::Cow, ops::DerefMut};

use std::fs::create_dir_all;
use std::path::PathBuf;
#[cfg(windows)]
use std::ptr::write_volatile;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use std::{
fs::create_dir_all,
path::PathBuf,
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
},
time::{Duration, Instant},
};

use log::{debug, error, info};

use crate::coverage_clients::endpoint::EndpointCoverageClient;
use crate::{
configuration::{Configuration, CrashCriterion},
coverage_clients::CoverageClient,
coverage_clients::{endpoint::EndpointCoverageClient, CoverageClient},
input::OpenApiInput,
monitors::CoverageMonitor,
openapi::{
Expand Down
4 changes: 1 addition & 3 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use crate::configuration::Configuration;
use anyhow::{Context, Result};
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use std::collections::HashMap;
use std::fs::File;
use std::str::FromStr;
use std::{collections::HashMap, fs::File, str::FromStr};

/// Load default headers from a file specified in configuration and apply
/// them to the given ClientBuilder
Expand Down
23 changes: 15 additions & 8 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,26 @@
use self::parameter::ParameterKind;
pub use self::{method::Method, parameter::ParameterContents};
use crate::openapi::{JsonContent, TextPlain, WwwForm};
use crate::{
openapi::find_operation, parameter_feedback::ParameterFeedback, state::HasRandAndOpenAPI,
openapi::{find_operation, JsonContent, TextPlain, WwwForm},
parameter_feedback::ParameterFeedback,
state::HasRandAndOpenAPI,
};
use ahash::RandomState;
use indexmap::map::ValuesMut;
use indexmap::{map::Iter, IndexMap};
use libafl::corpus::CorpusId;
use libafl::{inputs::Input, Error};
use indexmap::{
map::{Iter, ValuesMut},
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, hash::BuildHasher, hash::Hasher};
use std::{fs::File, io::Read, path::Path};
use std::{
borrow::Cow,
fs::File,
hash::{BuildHasher, Hasher},
io::Read,
path::Path,
};

pub mod method;
pub mod parameter;
Expand Down
9 changes: 3 additions & 6 deletions src/openapi/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
//! fuzzing target during normal fuzzing operation. These functions need an OpenAPI struct
//! to generate realistic requests for the given target.
use std::borrow::Cow;
use std::{collections::VecDeque, f64::consts::PI};
use std::{borrow::Cow, collections::VecDeque, f64::consts::PI};

use indexmap::IndexMap;
use openapiv3::{
OpenAPI, Operation, Parameter, ParameterData, RefOr, Schema, SchemaKind, StringFormat, Type,
};
use petgraph::prelude::NodeIndex;
use petgraph::{csr::DefaultIx, graph::DiGraph, visit::EdgeRef};
use rand::prelude::Distribution;
use rand::Rng;
use petgraph::{csr::DefaultIx, graph::DiGraph, prelude::NodeIndex, visit::EdgeRef};
use rand::{prelude::Distribution, Rng};
use regex::Regex;
use serde_json::Value;
use unicode_truncate::UnicodeTruncateStr;
Expand Down
3 changes: 1 addition & 2 deletions src/openapi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::{Context, Result};
use indexmap::IndexMap;
use openapiv3::{MediaType, OpenAPI, Operation, PathItem, VersionedOpenAPI};
use std::fmt::Debug;
use std::{convert::TryFrom, path::Path};
use std::{convert::TryFrom, fmt::Debug, path::Path};

use crate::input::{method::InvalidMethodError, Method};

Expand Down
8 changes: 3 additions & 5 deletions src/openapi_mutator/add_request.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Mutates a request series by adding a new request to it. The new request is taken
//! at random from the API specification.
use crate::openapi::JsonContent;
use crate::{
input::{
new_rand_input, parameter::ParameterKind, Body, OpenApiInput, OpenApiRequest,
ParameterContents,
},
openapi::JsonContent,
state::HasRandAndOpenAPI,
};
use indexmap::IndexMap;
Expand All @@ -15,11 +15,9 @@ use libafl::{
mutators::{MutationResult, Mutator},
Error,
};
use libafl_bolts::rands::Rand;
use libafl_bolts::Named;
use libafl_bolts::{rands::Rand, Named};
use openapiv3::{OpenAPI, RequestBody};
use std::borrow::Cow;
use std::convert::TryInto;
use std::{borrow::Cow, convert::TryInto};

/// The `AddRequestMutator` adds a request to a random path from the specification
/// to the series of requests. The request is added at the end of the series, and
Expand Down
6 changes: 2 additions & 4 deletions src/openapi_mutator/different_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ use libafl::{
mutators::{MutationResult, Mutator},
Error,
};
use libafl_bolts::rands::Rand;
use libafl_bolts::Named;
use std::borrow::Cow;
use std::convert::TryInto;
use libafl_bolts::{rands::Rand, Named};
use std::{borrow::Cow, convert::TryInto};

/// The `DifferentMethodMutator` changes an existing request from the series
/// to use a different method. Only methods available for the current path
Expand Down
8 changes: 5 additions & 3 deletions src/openapi_mutator/different_path.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//! Mutates a request series by changing the path and method on one of the HTTP requests.
//! The new path and method are taken from the API specification.
use crate::{input::fix_input_parameters, input::OpenApiInput, state::HasRandAndOpenAPI};
use crate::{
input::{fix_input_parameters, OpenApiInput},
state::HasRandAndOpenAPI,
};
pub use libafl::mutators::mutations::*;
use libafl::{
mutators::{MutationResult, Mutator},
Error,
};
use libafl_bolts::rands::Rand;
use libafl_bolts::Named;
use libafl_bolts::{rands::Rand, Named};
use std::{borrow::Cow, convert::TryInto};

/// The `DifferentPathMutator` changes an existing request from the series
Expand Down
3 changes: 1 addition & 2 deletions src/openapi_mutator/duplicate_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use libafl::{
state::HasRand,
Error,
};
use libafl_bolts::rands::Rand;
use libafl_bolts::Named;
use libafl_bolts::{rands::Rand, Named};

/// The `DuplicateRequestMutator` duplicates an existing request in the series.
pub struct DuplicateRequestMutator;
Expand Down
5 changes: 4 additions & 1 deletion src/openapi_mutator/establish_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use std::borrow::Cow;

use crate::{input::OpenApiInput, input::ParameterContents, state::HasRandAndOpenAPI};
use crate::{
input::{OpenApiInput, ParameterContents},
state::HasRandAndOpenAPI,
};
pub use libafl::mutators::mutations::*;
use libafl::{
mutators::{MutationResult, Mutator},
Expand Down
20 changes: 11 additions & 9 deletions src/openapi_mutator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
use core::num::NonZero;
use std::borrow::Cow;

use crate::input::parameter::SimpleValue;
use crate::input::{new_rand_input, OpenApiInput, ParameterContents};
use crate::state::OpenApiFuzzerState;
use libafl::corpus::Corpus;
use libafl::inputs::Input;
use crate::{
input::{new_rand_input, parameter::SimpleValue, OpenApiInput, ParameterContents},
state::OpenApiFuzzerState,
};
pub use libafl::mutators::mutations::*;
use libafl::{
inputs::{BytesInput, HasMutatorBytes},
corpus::Corpus,
inputs::{BytesInput, HasMutatorBytes, Input},
mutators::{MutationResult, Mutator},
state::HasRand,
Error,
};
use libafl_bolts::rands::Rand;
use libafl_bolts::tuples::{tuple_list, tuple_list_type};
use libafl_bolts::Named;
use libafl_bolts::{
rands::Rand,
tuples::{tuple_list, tuple_list_type},
Named,
};

pub mod add_request;
use add_request::AddRequestMutator;
Expand Down
Loading

0 comments on commit 9a75a6a

Please sign in to comment.