Beispiel #1
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);
        }
      }
    }
  }
}
Beispiel #2
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);
  }
}
Beispiel #3
0
void Fuzzer::Loop(size_t NumIterations) {
  for (size_t i = 1; i <= NumIterations; i++) {
    for (size_t J1 = 0; J1 < Corpus.size(); J1++) {
      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) {
        for (size_t J2 = 0; J2 < Corpus.size(); J2++) {
          CurrentUnit.clear();
          CrossOver(Corpus[J1], Corpus[J2], &CurrentUnit, Options.MaxLen);
          MutateAndTestOne(&CurrentUnit);
        }
      }
    }
  }
}
Beispiel #4
0
size_t Fuzzer::Loop(size_t NumIterations) {
  size_t NewUnits = 0;
  for (size_t i = 1; i <= NumIterations; i++) {
    if (Options.DoCrossOver) {
      for (size_t J1 = 0; J1 < Corpus.size(); J1++) {
        for (size_t J2 = 0; J2 < Corpus.size(); J2++) {
          CurrentUnit.clear();
          CrossOver(Corpus[J1], Corpus[J2], &CurrentUnit, Options.MaxLen);
          NewUnits += MutateAndTestOne(&CurrentUnit);
        }
      }
    } else {  // No CrossOver
      for (size_t J = 0; J < Corpus.size(); J++) {
        CurrentUnit = Corpus[J];
        NewUnits += MutateAndTestOne(&CurrentUnit);
      }
    }
  }
  return NewUnits;
}
Beispiel #5
0
void Fuzzer::Loop() {
  system_clock::time_point LastCorpusReload = system_clock::now();
  if (Options.DoCrossOver)
    MD.SetCorpus(&Corpus);
  while (true) {
    auto Now = system_clock::now();
    if (duration_cast<seconds>(Now - LastCorpusReload).count()) {
      RereadOutputCorpus(Options.MaxLen);
      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");
  MD.PrintRecommendedDictionary();
}