Skip to content

Commit

Permalink
Use use
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasTNO committed Dec 9, 2024
1 parent f2e0a49 commit 486edb1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/openapi_mutator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! reorder them, for instance. And there are other mutators that act on the contents of a
//! request, changing the parameter values (using a LibAFL byte sequence mutator, for example).
use core::num::NonZero;
use std::borrow::Cow;

use crate::input::parameter::SimpleValue;
Expand Down Expand Up @@ -214,7 +215,7 @@ fn mutate_number<S: HasRand>(state: &mut S, n: &mut serde_json::value::Number) -
// A small chance to get a special value that might just lead to interesting errors
match state
.rand_mut()
.below(core::num::NonZero::new(100).unwrap())
.below(NonZero::new(100).unwrap())
{
0 => {
*n = (-1).into();
Expand All @@ -231,19 +232,19 @@ fn mutate_number<S: HasRand>(state: &mut S, n: &mut serde_json::value::Number) -
0 => 0.into(),
x_usz => state
.rand_mut()
.below(core::num::NonZero::new(x_usz.saturating_mul(2)).unwrap())
.below(NonZero::new(x_usz.saturating_mul(2)).unwrap())
.into(),
};
return MutationResult::Mutated;
};
if let Some(x) = n.as_i64() {
// always negative
*n = (state.rand_mut().below(
core::num::NonZero::new(x)
.unwrap_or(core::num::NonZero::new(i64::MAX).unwrap()) // because -i64::MIN == i64::MIN
.saturating_mul(core::num::NonZero::new(4).unwrap())
NonZero::new(x)
.unwrap_or(NonZero::new(i64::MAX).unwrap()) // because -i64::MIN == i64::MIN
.saturating_mul(NonZero::new(4).unwrap())
.try_into()
.unwrap_or(core::num::NonZero::new(usize::MAX).unwrap()), // larger values could otherwise be truncated
.unwrap_or(NonZero::new(usize::MAX).unwrap()), // larger values could otherwise be truncated
) as i64
+ x.saturating_mul(2))
.into();
Expand All @@ -258,7 +259,7 @@ fn mutate_number<S: HasRand>(state: &mut S, n: &mut serde_json::value::Number) -
0 => 0,
x_usz => state
.rand_mut()
.below(core::num::NonZero::new(x_usz.saturating_mul(4)).unwrap()),
.below(NonZero::new(x_usz.saturating_mul(4)).unwrap()),
};
let n_new = serde_json::value::Number::from_f64((x_int_new as f64) - 2.0 * x);
if let Some(n_new) = n_new {
Expand Down Expand Up @@ -369,7 +370,7 @@ where
from.into_iter()
.zip(1..)
.fold(None, |result, (element, count)| {
match rand.below(core::num::NonZero::new(count).unwrap()) {
match rand.below(NonZero::new(count).unwrap()) {
0 => Some(element),
_ => result,
}
Expand Down

0 comments on commit 486edb1

Please sign in to comment.