Global Metrics
path: .metrics.cognitive.sum
old: 0.0
new: 35.0
path: .metrics.cognitive.average
old: 0.0
new: 1.9444444444444444
path: .metrics.mi.mi_visual_studio
old: 39.55515209252757
new: 17.13460230908362
path: .metrics.mi.mi_sei
old: 50.8414156209889
new: -5.727857294197825
path: .metrics.mi.mi_original
old: 67.63931007822214
new: 29.300169948532982
path: .metrics.cyclomatic.sum
old: 3.0
new: 56.0
path: .metrics.cyclomatic.average
old: 1.0
new: 2.4347826086956523
path: .metrics.loc.ploc
old: 36.0
new: 148.0
path: .metrics.loc.sloc
old: 58.0
new: 185.0
path: .metrics.loc.cloc
old: 9.0
new: 16.0
path: .metrics.loc.blank
old: 13.0
new: 21.0
path: .metrics.loc.lloc
old: 18.0
new: 72.0
path: .metrics.nom.total
old: 2.0
new: 18.0
path: .metrics.nom.functions
old: 2.0
new: 18.0
path: .metrics.nexits.average
old: 0.0
new: 0.8333333333333334
path: .metrics.nexits.sum
old: 0.0
new: 15.0
path: .metrics.nargs.average
old: 2.0
new: 1.5555555555555556
path: .metrics.nargs.sum
old: 4.0
new: 28.0
path: .metrics.halstead.N2
old: 107.0
new: 261.0
path: .metrics.halstead.n2
old: 35.0
new: 129.0
path: .metrics.halstead.volume
old: 1205.3457808140474
new: 4962.31684439703
path: .metrics.halstead.N1
old: 110.0
new: 421.0
path: .metrics.halstead.effort
old: 22109.48546521767
new: 130520.47327937304
path: .metrics.halstead.estimated_program_length
old: 222.5444556017277
new: 1026.659748621268
path: .metrics.halstead.purity_ratio
old: 1.0255504866439065
new: 1.50536620032444
path: .metrics.halstead.n1
old: 12.0
new: 26.0
path: .metrics.halstead.difficulty
old: 18.34285714285714
new: 26.302325581395348
path: .metrics.halstead.level
old: 0.0545171339563863
new: 0.03801945181255526
path: .metrics.halstead.time
old: 1228.3047480676482
new: 7251.137404409613
path: .metrics.halstead.length
old: 217.0
new: 682.0
path: .metrics.halstead.vocabulary
old: 47.0
new: 155.0
path: .metrics.halstead.bugs
old: 0.2625817282604864
new: 0.857691629923851
Spaces Data
Minimal test - lines (30, 183)
path: .spaces[0].metrics.mi.mi_original
old: 92.98911218378564
new: 32.57348393094489
path: .spaces[0].metrics.mi.mi_visual_studio
old: 54.3795977682957
new: 19.04882101224847
path: .spaces[0].metrics.mi.mi_sei
old: 83.2434411119633
new: -9.330451083738351
path: .spaces[0].metrics.loc.blank
old: 4.0
new: 21.0
path: .spaces[0].metrics.loc.ploc
old: 12.0
new: 128.0
path: .spaces[0].metrics.loc.cloc
old: 2.0
new: 5.0
path: .spaces[0].metrics.loc.lloc
old: 5.0
new: 72.0
path: .spaces[0].metrics.loc.sloc
old: 18.0
new: 154.0
path: .spaces[0].metrics.halstead.n1
old: 10.0
new: 26.0
path: .spaces[0].metrics.halstead.bugs
old: 0.0716284875665669
new: 0.8613053948565235
path: .spaces[0].metrics.halstead.difficulty
old: 8.181818181818182
new: 26.838709677419356
path: .spaces[0].metrics.halstead.volume
old: 385.0
new: 4893.910253465711
path: .spaces[0].metrics.halstead.N2
old: 36.0
new: 256.0
path: .spaces[0].metrics.halstead.effort
old: 3150.0
new: 131346.236480112
path: .spaces[0].metrics.halstead.estimated_program_length
old: 131.32677655889415
new: 984.5317751596408
path: .spaces[0].metrics.halstead.N1
old: 41.0
new: 421.0
path: .spaces[0].metrics.halstead.time
old: 175.0
new: 7297.013137784001
path: .spaces[0].metrics.halstead.n2
old: 22.0
new: 124.0
path: .spaces[0].metrics.halstead.level
old: 0.12222222222222222
new: 0.037259615384615384
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.705542552712911
new: 1.4542566841353632
path: .spaces[0].metrics.halstead.length
old: 77.0
new: 677.0
path: .spaces[0].metrics.halstead.vocabulary
old: 32.0
new: 150.0
path: .spaces[0].metrics.nargs.sum
old: 2.0
new: 28.0
path: .spaces[0].metrics.nargs.average
old: 2.0
new: 1.5555555555555556
path: .spaces[0].metrics.cognitive.average
old: 0.0
new: 1.9444444444444444
path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 35.0
path: .spaces[0].metrics.nexits.average
old: 0.0
new: 0.8333333333333334
path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 15.0
path: .spaces[0].metrics.nom.total
old: 1.0
new: 18.0
path: .spaces[0].metrics.nom.functions
old: 1.0
new: 18.0
path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 55.0
path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 2.5
Code
namespace fuzzer {
static void AlarmHandler(int, siginfo_t *, void *) {
Fuzzer::StaticAlarmCallback();
}
static void (*upstream_segv_handler)(int, siginfo_t *, void *);
static void SegvHandler(int sig, siginfo_t *si, void *ucontext) {
assert(si->si_signo == SIGSEGV);
if (upstream_segv_handler)
return upstream_segv_handler(sig, si, ucontext);
Fuzzer::StaticCrashSignalCallback();
}
static void CrashHandler(int, siginfo_t *, void *) {
Fuzzer::StaticCrashSignalCallback();
}
static void InterruptHandler(int, siginfo_t *, void *) {
Fuzzer::StaticInterruptCallback();
}
static void GracefulExitHandler(int, siginfo_t *, void *) {
Fuzzer::StaticGracefulExitCallback();
}
static void FileSizeExceedHandler(int, siginfo_t *, void *) {
Fuzzer::StaticFileSizeExceedCallback();
}
static void SetSigaction(int signum,
void (*callback)(int, siginfo_t *, void *)) {
struct sigaction sigact = {};
if (sigaction(signum, nullptr, &sigact)) {
Printf("libFuzzer: sigaction failed with %d\n", errno);
exit(1);
}
if (sigact.sa_flags & SA_SIGINFO) {
if (sigact.sa_sigaction) {
if (signum != SIGSEGV)
return;
upstream_segv_handler = sigact.sa_sigaction;
}
} else {
if (sigact.sa_handler != SIG_DFL && sigact.sa_handler != SIG_IGN &&
sigact.sa_handler != SIG_ERR)
return;
}
sigact = {};
sigact.sa_flags = SA_SIGINFO;
sigact.sa_sigaction = callback;
if (sigaction(signum, &sigact, 0)) {
Printf("libFuzzer: sigaction failed with %d\n", errno);
exit(1);
}
}
// Return true on success, false otherwise.
bool ExecuteCommand(const Command &Cmd, std::string *CmdOutput) {
FILE *Pipe = popen(Cmd.toString().c_str(), "r");
if (!Pipe)
return false;
if (CmdOutput) {
char TmpBuffer[128];
while (fgets(TmpBuffer, sizeof(TmpBuffer), Pipe))
CmdOutput->append(TmpBuffer);
}
return pclose(Pipe) == 0;
}
void SetTimer(int Seconds) {
struct itimerval T {
{Seconds, 0}, { Seconds, 0 }
};
if (setitimer(ITIMER_REAL, &T, nullptr)) {
Printf("libFuzzer: setitimer failed with %d\n", errno);
exit(1);
}
SetSigaction(SIGALRM, AlarmHandler);
}
void SetSignalHandler(const FuzzingOptions& Options) {
// setitimer is not implemented in emscripten.
if (Options.UnitTimeoutSec > 0 && !LIBFUZZER_EMSCRIPTEN)
SetTimer(Options.UnitTimeoutSec / 2 + 1);
if (Options.HandleInt)
SetSigaction(SIGINT, InterruptHandler);
if (Options.HandleTerm)
SetSigaction(SIGTERM, InterruptHandler);
if (Options.HandleSegv)
SetSigaction(SIGSEGV, SegvHandler);
if (Options.HandleBus)
SetSigaction(SIGBUS, CrashHandler);
if (Options.HandleAbrt)
SetSigaction(SIGABRT, CrashHandler);
if (Options.HandleIll)
SetSigaction(SIGILL, CrashHandler);
if (Options.HandleFpe)
SetSigaction(SIGFPE, CrashHandler);
if (Options.HandleXfsz)
SetSigaction(SIGXFSZ, FileSizeExceedHandler);
if (Options.HandleUsr1)
SetSigaction(SIGUSR1, GracefulExitHandler);
if (Options.HandleUsr2)
SetSigaction(SIGUSR2, GracefulExitHandler);
}
void SleepSeconds(int Seconds) {
sleep(Seconds); // Use C API to avoid coverage from instrumented libc++.
}
unsigned long GetPid() { return (unsigned long)getpid(); }
size_t GetPeakRSSMb() {
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage))
return 0;
if (LIBFUZZER_LINUX || LIBFUZZER_FREEBSD || LIBFUZZER_NETBSD ||
LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN) {
// ru_maxrss is in KiB
return usage.ru_maxrss >> 10;
} else if (LIBFUZZER_APPLE) {
// ru_maxrss is in bytes
return usage.ru_maxrss >> 20;
}
assert(0 && "GetPeakRSSMb() is not implemented for your platform");
return 0;
}
FILE *OpenProcessPipe(const char *Command, const char *Mode) {
return popen(Command, Mode);
}
int CloseProcessPipe(FILE *F) {
return pclose(F);
}
const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
size_t PattLen) {
return memmem(Data, DataLen, Patt, PattLen);
}
std::string DisassembleCmd(const std::string &FileName) {
return "objdump -d " + FileName;
}
std::string SearchRegexCmd(const std::string &Regex) {
return "grep '" + Regex + "'";
}
} // namespace fuzzer