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

Introduce LLVMFuzzerInitialize support #128

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

zi0Black
Copy link

@zi0Black zi0Black commented Dec 21, 2024

  • Added example_init to demonstrate the use of initialization code with the fuzz_target! macro.
  • Updated fuzz_target! macro to support an init parameter for executing initialization code before fuzzing.
  • Updated CI script to build and run the new example.

Should I update any doc with init usage example?

Is the example good enough? Maybe an example using static would be more meaningful.

Close after merge:

- Added `example_init` to demonstrate the use of initialization code with the `fuzz_target!` macro.
- Updated `fuzz_target!` macro to support an `init` parameter for executing initialization code before fuzzing.
- Updated CI script to build and run the new example.
Copy link

@hanna-kruppe hanna-kruppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this before I got around to it! Some questions/suggestions I had while skimming the diff. I'm not a maintainer, so this doesn't carry any weight one way or another, but I hope they're still useful.

example_init/fuzz/fuzz_targets/bigbang.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@@ -198,9 +185,31 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
/// `"arbitrary-derive"` cargo feature.
#[macro_export]
macro_rules! fuzz_target {
(|$bytes:ident| $body:expr) => {
(init: $init:expr, |$bytes:ident| $body:expr) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using $init:expr matches the existing behavior for $body but I'm not sure if that's desirable. It permits all sorts of expressions, including those that return values, which may be misleading. This is code that's executed for side-effects, so $init:stmt seems more appropriate. However, non-block statements look strange to me in this position (fuzz_target!(init: let x = 0, |data| {}) without semicolon would be valid but meaningless). So maybe enforce that it's a block with $init:block and expand to let _: () = $init; so that it's required to not return anything meaningful?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll wait and see what the maintainers have to say, but I get your point, still I don't have a preference.

src/lib.rs Show resolved Hide resolved
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.

2 participants