#include "FuzzerInternal.h"
#include <sanitizer/coverage_interface.h>
#include <algorithm>
-#include <iostream>
namespace fuzzer {
} else {
auto T = SubstituteTokens(U);
T.push_back(0);
- std::cerr << T.data();
- std::cerr << PrintAfter;
+ Printf("%s%s", T.data(), PrintAfter);
}
}
}
void Fuzzer::DeathCallback() {
- std::cerr << "DEATH: " << std::endl;
+ Printf("DEATH:\n");
Print(CurrentUnit, "\n");
PrintUnitInASCIIOrTokens(CurrentUnit, "\n");
WriteToCrash(CurrentUnit, "crash-");
duration_cast<seconds>(system_clock::now() - UnitStartTime).count();
if (Seconds == 0) return;
if (Options.Verbosity >= 2)
- std::cerr << "AlarmCallback " << Seconds << "\n";
+ Printf("AlarmCallback %zd\n", Seconds);
if (Seconds >= (size_t)Options.UnitTimeoutSec) {
- std::cerr << "ALARM: working on the last Unit for " << Seconds << " seconds"
- << std::endl;
+ Printf("ALARM: working on the last Unit for %zd seconds\n", Seconds);
Print(CurrentUnit, "\n");
PrintUnitInASCIIOrTokens(CurrentUnit, "\n");
WriteToCrash(CurrentUnit, "timeout-");
if (!Options.Verbosity) return;
size_t Seconds = secondsSinceProcessStartUp();
size_t ExecPerSec = (Seconds ? TotalNumberOfRuns / Seconds : 0);
- std::cerr
- << "#" << TotalNumberOfRuns
- << "\t" << Where
- << " cov " << Cov
- << " bits " << TotalBits()
- << " units " << Corpus.size()
- << " exec/s " << ExecPerSec
- << End;
+ Printf("#%zd\t%s cov %zd bits %zd units %zd exec/s %zd %s", TotalNumberOfRuns,
+ Where, Cov, TotalBits(), Corpus.size(), ExecPerSec, End);
}
void Fuzzer::RereadOutputCorpus() {
}
if (!Options.Reload) return;
if (Options.Verbosity >= 2)
- std::cerr << "Reload: read " << AdditionalCorpus.size() << " new units.\n";
+ Printf("Reload: read %zd new units.\n", AdditionalCorpus.size());
for (auto &X : AdditionalCorpus) {
if (X.size() > (size_t)Options.MaxLen)
X.resize(Options.MaxLen);
(Options.PreferSmallDuringInitialShuffle == 1 ||
(Options.PreferSmallDuringInitialShuffle == -1 && rand() % 2));
if (Options.Verbosity)
- std::cerr << "PreferSmall: " << PreferSmall << "\n";
+ Printf("PreferSmall: %d\n", PreferSmall);
PrintStats("READ ", 0);
std::vector<Unit> NewCorpus;
std::random_shuffle(Corpus.begin(), Corpus.end());
MaxCov = NewCoverage;
NewCorpus.push_back(U);
if (Options.Verbosity >= 2)
- std::cerr << "NEW0: " << NewCoverage
- << " L " << U.size()
- << "\n";
+ Printf("NEW0: %zd L %zd\n", NewCoverage, U.size());
}
}
}
duration_cast<seconds>(UnitStopTime - UnitStartTime).count();
if (TimeOfUnit > TimeOfLongestUnitInSeconds) {
TimeOfLongestUnitInSeconds = TimeOfUnit;
- std::cerr << "Longest unit: " << TimeOfLongestUnitInSeconds
- << " s:\n";
+ Printf("Longest unit: %zd s:\n", TimeOfLongestUnitInSeconds);
Print(U, "\n");
}
return Res;
std::string Path = DirPlusFile(Options.OutputCorpus, Hash(U));
WriteToFile(U, Path);
if (Options.Verbosity >= 2)
- std::cerr << "Written to " << Path << std::endl;
+ Printf("Written to %s\n", Path.c_str());
}
void Fuzzer::WriteToCrash(const Unit &U, const char *Prefix) {
std::string Path = Prefix + Hash(U);
WriteToFile(U, Path);
- std::cerr << "CRASHED; file written to " << Path << std::endl;
- std::cerr << "Base64: ";
+ Printf("CRASHED; file written to %s\nBase64: ", Path.c_str());
PrintFileAsBase64(Path);
}
for (const auto &U : Corpus)
WriteToFile(U, DirPlusFile(Options.OutputCorpus, Hash(U)));
if (Options.Verbosity)
- std::cerr << "Written corpus of " << Corpus.size() << " files to "
- << Options.OutputCorpus << "\n";
+ Printf("Written corpus of %zd files to %s\n", Corpus.size(),
+ Options.OutputCorpus.c_str());
}
void Fuzzer::ReportNewCoverage(size_t NewCoverage, const Unit &U) {
UnitHashesAddedToCorpus.insert(Hash(U));
PrintStats("NEW ", NewCoverage, "");
if (Options.Verbosity) {
- std::cerr << " L: " << U.size();
+ Printf(" L: %zd", U.size());
if (U.size() < 30) {
- std::cerr << " ";
+ Printf(" ");
PrintUnitInASCIIOrTokens(U, "\t");
Print(U);
}
- std::cerr << "\n";
+ Printf("\n");
}
WriteToOutputCorpus(U);
if (Options.ExitOnFirst)
#include "FuzzerInternal.h"
#include <sstream>
#include <iomanip>
-#include <iostream>
#include <sys/time.h>
#include <cassert>
#include <cstring>
void Print(const Unit &v, const char *PrintAfter) {
for (auto x : v)
- std::cerr << "0x" << std::hex << (unsigned) x << std::dec << ",";
- std::cerr << PrintAfter;
+ Printf("0x%x,", (unsigned) x);
+ Printf("%s", PrintAfter);
}
void PrintASCII(const Unit &U, const char *PrintAfter) {
for (auto X : U) {
if (isprint(X))
- std::cerr << X;
+ Printf("%c", X);
else
- std::cerr << "\\x" << std::hex << (int)(unsigned)X << std::dec;
+ Printf("\\x%x", (unsigned)X);
}
- std::cerr << PrintAfter;
+ Printf("%s", PrintAfter);
}
std::string Hash(const Unit &U) {
void SetTimer(int Seconds) {
struct itimerval T {{Seconds, 0}, {Seconds, 0}};
- std::cerr << "SetTimer " << Seconds << "\n";
+ Printf("SetTimer %d\n", Seconds);
int Res = setitimer(ITIMER_REAL, &T, nullptr);
assert(Res == 0);
struct sigaction sigact;