Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower capped RAND generators #2671

Merged
merged 11 commits into from
Nov 11, 2024
Merged

Lower capped RAND generators #2671

merged 11 commits into from
Nov 11, 2024

Conversation

CowBoy4mH3LL
Copy link
Contributor

Basically, there is a min_size aside from the max_size in the RAND generators (RandBytesGenerator and RandPrintablesGenerator).
This allows to generate rand bytes sequences from min_size to max_size, e.g. between 2 bytes and 4 bytes or 1 byte and 1 byte for that matter.
Becomes extremely useful if we are aware of the recipient's acceptance bounds.
If not, simply keep min_size as 1 and the older behavior is restored.

@CowBoy4mH3LL CowBoy4mH3LL changed the title Lower capped RADN generators Lower capped RAND generators Nov 8, 2024
@tokatoka
Copy link
Member

tokatoka commented Nov 8, 2024

good.
but can you not to change the original constructor? which sets the min_size to the default value of 1
and make another constructor for you, that takes two args (min and max)

@domenukk
Copy link
Member

domenukk commented Nov 8, 2024

Yes let's add a with_min_size constructor instead of changing the existing API

@CowBoy4mH3LL
Copy link
Contributor Author

CowBoy4mH3LL commented Nov 8, 2024

Sounds good!! Ill make that change.
I that case though, do we need new test cases showing this new constructor?

@domenukk
Copy link
Member

domenukk commented Nov 8, 2024

You can change one of them, for example baby_fuzzer_custom_input or any other of your choice :)

@domenukk
Copy link
Member

domenukk commented Nov 9, 2024

Nice thx! :)
Clippy is still a bit unhappy:

error: this method could have a `#[must_use]` attribute
   --> libafl/src/generators/mod.rs:108:5
    |
108 |     pub fn with_min_size(min_size: NonZeroUsize, max_size: NonZeroUsize) -> Self {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_min_size(min_size: NonZeroUsize, max_size: NonZeroUsize) -> Self`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate
    = note: `-D clippy::must-use-candidate` implied by `-D clippy::pedantic`
    = help: to override `-D clippy::pedantic` add `#[allow(clippy::must_use_candidate)]`

error: this method could have a `#[must_use]` attribute
   --> libafl/src/generators/mod.rs:148:5
    |
148 |     pub fn with_min_size(min_size: NonZeroUsize, max_size: NonZeroUsize) -> Self {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_min_size(min_size: NonZeroUsize, max_size: NonZeroUsize) -> Self`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate

@CowBoy4mH3LL
Copy link
Contributor Author

  1. Semantically are two must_use attributes allowed for the same struct?
  2. Can you help me with this one error - can't seem to relate to any code I introduced -- https://github.com/AFLplusplus/LibAFL/actions/runs/11757949843/job/32755797517?pr=2671

@domenukk
Copy link
Member

The second error isn't related to your changes, sorry :)
For must_use it's not struct related at all, but for a method.
So just change

 pub fn with_min_size(min_size: NonZeroUsize, max_size: NonZeroUsize) -> Self {

to

#[must_use]
 pub fn with_min_size(min_size: NonZeroUsize, max_size: NonZeroUsize) -> Self {

That should be all :)

@CowBoy4mH3LL
Copy link
Contributor Author

Done on this one!!
Thanks guys!!
BTW, the Papa Roach stegos in the code must stay :)

@domenukk domenukk merged commit e25094e into AFLplusplus:main Nov 11, 2024
100 checks passed
@domenukk
Copy link
Member

Thank you!

riesentoaster pushed a commit to riesentoaster/LibAFL that referenced this pull request Nov 21, 2024
* Lower capped rand generators

* Updated all references to RAND generators

* Formatting updates

* New RAND bytes generator constructor

* Revert "Updated all references to RAND generators"

This reverts commit 9daad89.

* Revert "Formatting updates"

This reverts commit ff2a61a.

* cargo nightly format

* Added must_use to with_min_size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants