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

Allow running initialization code before fuzz_target! code #110

Open
mgeisler opened this issue Jun 7, 2023 · 1 comment
Open

Allow running initialization code before fuzz_target! code #110

mgeisler opened this issue Jun 7, 2023 · 1 comment

Comments

@mgeisler
Copy link

mgeisler commented Jun 7, 2023

Hi there,

I'm working on a fuzzer for which I would like to initialize a mutable variable once at the start of the program. I will then use this repeatedly in my fuzzing loop.

Since I believe the fuzzing loop is single threaded, it ought to be simple and safe to setup such a variable at the start of my program. However, due to how fuzz_target! expands, I don't think I can do this without using statics? I was thinking to use LLVMFuzzerInitialize, but then I saw that it's actually used already by libfuzzer 🙂 This was also touched upon in #46.

I started using a static mut with a OnceCell, but I was immediately told that I'm leaking memory. I was hoping that it would be okay since I expect the static to be dropped as part of the program cleanup when the fuzzing loops stops? However, I see a few hundred messages saying both

Direct leak of 40968 byte(s) in 1 object(s) allocated from:
Direct leak of 30728 byte(s) in 1 object(s) allocated from:
Direct leak of 30728 byte(s) in 1 object(s) allocated from:

and

Indirect leak of 65556 byte(s) in 1 object(s) allocated from:
Indirect leak of 49192 byte(s) in 2 object(s) allocated from:
Indirect leak of 36530 byte(s) in 2 object(s) allocated from:

After all these messages, the fuzzer found a problem and I exited out of the fuzzing loop with a panic!.

Is there a better way to do expensive initialization of a mutable variable?

@darosior
Copy link

I agree it would be super useful.

There were a couple attempts (#33, #51) but it seems like the contributors / maintainers lost interest in this.

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

No branches or pull requests

2 participants