Esempio n. 1
0
void Fuzzer::Loop() {
  while (true) {
    size_t J1 = ChooseUnitIdxToMutate();;
    SyncCorpus();
    RereadOutputCorpus();
    if (TotalNumberOfRuns >= Options.MaxNumberOfRuns)
      return;
    if (Options.MaxTotalTimeSec > 0 &&
        secondsSinceProcessStartUp() >
        static_cast<size_t>(Options.MaxTotalTimeSec))
      return;
    CurrentUnit = Corpus[J1];
    // Optionally, cross with another unit.
    if (Options.DoCrossOver && USF.GetRand().RandBool()) {
      size_t J2 = ChooseUnitIdxToMutate();
      if (!Corpus[J1].empty() && !Corpus[J2].empty()) {
        assert(!Corpus[J2].empty());
        CurrentUnit.resize(Options.MaxLen);
        size_t NewSize = USF.CrossOver(
            Corpus[J1].data(), Corpus[J1].size(), Corpus[J2].data(),
            Corpus[J2].size(), CurrentUnit.data(), CurrentUnit.size());
        assert(NewSize > 0 && "CrossOver returned empty unit");
        assert(NewSize <= (size_t)Options.MaxLen &&
               "CrossOver returned overisized unit");
        CurrentUnit.resize(NewSize);
      }
    }
    // Perform several mutations and runs.
    MutateAndTestOne(&CurrentUnit);
  }
}
Esempio n. 2
0
void Fuzzer::Loop(size_t NumIterations) {
  for (size_t i = 1; i <= NumIterations; i++) {
    for (size_t J1 = 0; J1 < Corpus.size(); J1++) {
      SyncCorpus();
      RereadOutputCorpus();
      if (TotalNumberOfRuns >= Options.MaxNumberOfRuns)
        return;
      // First, simply mutate the unit w/o doing crosses.
      CurrentUnit = Corpus[J1];
      MutateAndTestOne(&CurrentUnit);
      // Now, cross with others.
      if (Options.DoCrossOver && !Corpus[J1].empty()) {
        for (size_t J2 = 0; J2 < Corpus.size(); J2++) {
          CurrentUnit.resize(Options.MaxLen);
          size_t NewSize = USF.CrossOver(
              Corpus[J1].data(), Corpus[J1].size(), Corpus[J2].data(),
              Corpus[J2].size(), CurrentUnit.data(), CurrentUnit.size());
          assert(NewSize > 0 && "CrossOver returned empty unit");
          assert(NewSize <= (size_t)Options.MaxLen &&
                 "CrossOver return overisized unit");
          CurrentUnit.resize(NewSize);
          MutateAndTestOne(&CurrentUnit);
        }
      }
    }
  }
}
Esempio n. 3
0
void Fuzzer::Loop() {
  system_clock::time_point LastCorpusReload = system_clock::now();
  if (Options.DoCrossOver)
    USF.SetCorpus(&Corpus);
  while (true) {
    SyncCorpus();
    auto Now = system_clock::now();
    if (duration_cast<seconds>(Now - LastCorpusReload).count()) {
      RereadOutputCorpus();
      LastCorpusReload = Now;
    }
    if (TotalNumberOfRuns >= Options.MaxNumberOfRuns)
      break;
    if (Options.MaxTotalTimeSec > 0 &&
        secondsSinceProcessStartUp() >
        static_cast<size_t>(Options.MaxTotalTimeSec))
      break;
    // Perform several mutations and runs.
    MutateAndTestOne();
  }

  PrintStats("DONE  ", "\n");
}