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

Using restarting manager with a command executor #1219

Closed
momvart opened this issue Apr 19, 2023 · 2 comments
Closed

Using restarting manager with a command executor #1219

momvart opened this issue Apr 19, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@momvart
Copy link
Contributor

momvart commented Apr 19, 2023

In our project, we are setting up a fuzzer with a restarting manager. Also, instead of using an InProcessExecutor we need to run an executable binary, so we want to use the CommandExecutor.
However, writing the fuzzer in this way gives a compilation error regarding some trait bounds are not satisfied.

To Reproduce
Minimizing the scenario, I have reached the following example.

pub fn main() {
    let monitor = MultiMonitor::new(|s| println!("{s}"));
    let (state, mut mgr) =
        match setup_restarting_mgr_std(monitor, 1111, EventConfig::from_name("default")) {
            Ok(res) => res,
            Err(err) => match err {
                Error::ShuttingDown => {
                    return;
                }
                _ => {
                    panic!("Failed to setup the restarter: {err}");
                }
            },
        };
    // ...
    let mut state = state.unwrap_or_else(|| {
        StdState::new(
            StdRand::with_seed(current_nanos()),
            InMemoryCorpus::new(),
            OnDiskCorpus::new(PathBuf::from("./crashes")).unwrap(),
            &mut feedback,
            &mut objective,
        )
        .unwrap()
    });

    let mut fuzzer = StdFuzzer::new(scheduler, feedback, objective);

    let mut executor = CommandExecutor::builder()
        .arg_input_arg()
        .program("./test_command")
        .build(())
        .unwrap();
    // ...
    fuzzer
        .fuzz_loop(&mut stages, &mut executor, &mut state, &mut mgr)
        .unwrap();
}
Full example

pub fn main() {
    let monitor = MultiMonitor::new(|s| println!("{s}"));

    let (state, mut mgr) =
        match setup_restarting_mgr_std(monitor, 1111, EventConfig::from_name("default")) {
            Ok(res) => res,
            Err(err) => match err {
                Error::ShuttingDown => {
                    return;
                }
                _ => {
                    panic!("Failed to setup the restarter: {err}");
                }
            },
        };

    let mut feedback = ConstFeedback::True;
    let mut objective = CrashFeedback::new();

    let mut state = state.unwrap_or_else(|| {
        StdState::new(
            StdRand::with_seed(current_nanos()),
            InMemoryCorpus::new(),
            OnDiskCorpus::new(PathBuf::from("./crashes")).unwrap(),
            &mut feedback,
            &mut objective,
        )
        .unwrap()
    });

    let scheduler = QueueScheduler::new();
    let mut fuzzer = StdFuzzer::new(scheduler, feedback, objective);

    let mut executor = CommandExecutor::builder()
        .arg_input_arg()
        .program("./test_command")
        .build(())
        .unwrap();

    let mut generator = RandPrintablesGenerator::new(32);
    state
        .generate_initial_inputs(&mut fuzzer, &mut executor, &mut generator, &mut mgr, 8)
        .unwrap();

    let mutator = StdScheduledMutator::new(havoc_mutations());
    let mut stages = tuple_list!(StdMutationalStage::new(mutator));

    fuzzer
        .fuzz_loop(&mut stages, &mut executor, &mut state, &mut mgr)
        .unwrap();
}

which gives the following compile error at the last step.

error[E0277]: the trait bound `CommandExecutor<LlmpRestartingEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, (), StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, StdCommandConfigurator, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>: Executor<LlmpEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>` is not satisfied
   --> src/restarting.rs:101:33
    |
101 |         .fuzz_loop(&mut stages, &mut executor, &mut state, &mut mgr)
    |          ---------              ^^^^^^^^^^^^^ the trait `Executor<LlmpEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>` is not implemented for `CommandExecutor<LlmpRestartingEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, (), StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, StdCommandConfigurator, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>`
    |          |
    |          required by a bound introduced by this call
    |
    = help: the trait `Executor<EM, Z>` is implemented for `CommandExecutor<EM, OT, S, T, Z>`
    = note: required for `LlmpRestartingEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, ...>, ...>` to implement `EventProcessor<CommandExecutor<LlmpRestartingEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, (), StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, StdCommandConfigurator, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>`
    = note: the full type name has been written to '.../baby_fuzzer-5d2cae3cc286ad0f.long-type-13577678708692025691.txt'
    = note: required for `StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, ...>>, ..., ..., ...>` to implement `Fuzzer<CommandExecutor<LlmpRestartingEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, (), StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, StdCommandConfigurator, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>, LlmpRestartingEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, (StdMutationalStage<CommandExecutor<LlmpRestartingEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, (), StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, StdCommandConfigurator, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>, LlmpRestartingEventManager<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>, unix_shmem::default::CommonUnixShMemProvider>, BytesInput, StdScheduledMutator<BytesInput, (BitFlipMutator, (ByteFlipMutator, (ByteIncMutator, (ByteDecMutator, (ByteNegMutator, (ByteRandMutator, (ByteAddMutator, (WordAddMutator, (DwordAddMutator, (QwordAddMutator, (ByteInterestingMutator, (WordInterestingMutator, (DwordInterestingMutator, (BytesDeleteMutator, (BytesDeleteMutator, (BytesDeleteMutator, (BytesDeleteMutator, (BytesExpandMutator, (BytesInsertMutator, (BytesRandInsertMutator, (BytesSetMutator, (BytesRandSetMutator, (BytesCopyMutator, (BytesInsertCopyMutator, (BytesSwapMutator, (CrossoverInsertMutator, (CrossoverReplaceMutator, ()))))))))))))))))))))))))))), StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, StdFuzzer<QueueScheduler<StdState<BytesInput, InMemoryCorpus<BytesInput>, RomuDuoJrRand, OnDiskCorpus<BytesInput>>>, ConstFeedback, CrashFeedback, ()>>, ())>`
    = note: the full type name has been written to '.../baby_fuzzer-5d2cae3cc286ad0f.long-type-2807299872897195628.txt'

Expected behavior
Being able to replace the InProcessExecutor with other types of executors. In other words, the manager should be independently set from the executor.

Additional context
Replacing the manager or the executor solves the issue.

@momvart momvart added the bug Something isn't working label Apr 19, 2023
@tokatoka
Copy link
Member

#1222 fixes it

@tokatoka
Copy link
Member

tokatoka commented Apr 20, 2023

thanks for the reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants