Global Metrics

path: .metrics.nom.functions
old: 33.0
new: 6.0

path: .metrics.nom.total
old: 36.0
new: 6.0

path: .metrics.nom.closures
old: 3.0
new: 0.0

path: .metrics.nexits.average
old: 0.9444444444444444
new: 0.16666666666666666

path: .metrics.nexits.sum
old: 34.0
new: 1.0

path: .metrics.cyclomatic.sum
old: 82.0
new: 14.0

path: .metrics.cyclomatic.average
old: 2.102564102564102
new: 1.5555555555555556

path: .metrics.loc.cloc
old: 40.0
new: 19.0

path: .metrics.loc.blank
old: 112.0
new: 15.0

path: .metrics.loc.ploc
old: 599.0
new: 57.0

path: .metrics.loc.lloc
old: 194.0
new: 21.0

path: .metrics.loc.sloc
old: 751.0
new: 91.0

path: .metrics.halstead.length
old: 3075.0
new: 220.0

path: .metrics.halstead.estimated_program_length
old: 2709.812731425597
new: 333.72414129577294

path: .metrics.halstead.effort
old: 1898211.597354593
new: 18587.755102040817

path: .metrics.halstead.n2
old: 305.0
new: 49.0

path: .metrics.halstead.level
old: 0.013636465249368476
new: 0.07101449275362319

path: .metrics.halstead.N2
old: 1209.0
new: 92.0

path: .metrics.halstead.bugs
old: 5.110246234757284
new: 0.2338999020230108

path: .metrics.halstead.time
old: 105456.19985303294
new: 1032.6530612244896

path: .metrics.halstead.difficulty
old: 73.3327868852459
new: 14.081632653061224

path: .metrics.halstead.purity_ratio
old: 0.8812399126587308
new: 1.5169279149807862

path: .metrics.halstead.vocabulary
old: 342.0
new: 64.0

path: .metrics.halstead.volume
old: 25884.896483274133
new: 1320.0

path: .metrics.halstead.N1
old: 1866.0
new: 128.0

path: .metrics.halstead.n1
old: 37.0
new: 15.0

path: .metrics.cognitive.sum
old: 26.0
new: 6.0

path: .metrics.cognitive.average
old: 0.7222222222222222
new: 1.0

path: .metrics.nargs.average
old: 1.6666666666666667
new: 0.5

path: .metrics.nargs.sum
old: 60.0
new: 3.0

path: .metrics.mi.mi_sei
old: -61.346121999275354
new: 40.96020929803942

path: .metrics.mi.mi_visual_studio
old: 0.0
new: 33.53220088503443

path: .metrics.mi.mi_original
old: -7.966129195760104
new: 57.34006351340888

Spaces Data

Minimal test - lines (14, 91)

path: .spaces[0].metrics.loc.cloc
old: 0.0
new: 14.0

path: .spaces[0].metrics.loc.lloc
old: 1.0
new: 21.0

path: .spaces[0].metrics.loc.sloc
old: 8.0
new: 78.0

path: .spaces[0].metrics.loc.ploc
old: 8.0
new: 52.0

path: .spaces[0].metrics.loc.blank
old: 0.0
new: 12.0

path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 13.0

path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 1.625

path: .spaces[0].metrics.nom.functions
old: 1.0
new: 6.0

path: .spaces[0].metrics.nom.total
old: 1.0
new: 6.0

path: .spaces[0].metrics.cognitive.average
old: 0.0
new: 1.0

path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 6.0

path: .spaces[0].metrics.nexits.average
old: 0.0
new: 0.16666666666666666

path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 1.0

path: .spaces[0].metrics.halstead.bugs
old: 0.053385531594046416
new: 0.23494965519069225

path: .spaces[0].metrics.halstead.vocabulary
old: 26.0
new: 60.0

path: .spaces[0].metrics.halstead.volume
old: 263.22462421590114
new: 1275.88836865144

path: .spaces[0].metrics.halstead.purity_ratio
old: 1.7260197631988936
new: 1.415447908652607

path: .spaces[0].metrics.halstead.length
old: 56.0
new: 216.0

path: .spaces[0].metrics.halstead.time
old: 112.60164480346884
new: 1039.612744827099

path: .spaces[0].metrics.halstead.level
old: 0.12987012987012986
new: 0.06818181818181819

path: .spaces[0].metrics.halstead.estimated_program_length
old: 96.65710673913804
new: 305.73674826896314

path: .spaces[0].metrics.halstead.n2
old: 15.0
new: 45.0

path: .spaces[0].metrics.halstead.effort
old: 2026.829606462439
new: 18713.029406887785

path: .spaces[0].metrics.halstead.N2
old: 21.0
new: 88.0

path: .spaces[0].metrics.halstead.N1
old: 35.0
new: 128.0

path: .spaces[0].metrics.halstead.difficulty
old: 7.7
new: 14.666666666666666

path: .spaces[0].metrics.halstead.n1
old: 11.0
new: 15.0

path: .spaces[0].metrics.nargs.average
old: 1.0
new: 0.5

path: .spaces[0].metrics.nargs.sum
old: 1.0
new: 3.0

path: .spaces[0].metrics.mi.mi_original
old: 108.10340671373008
new: 60.24404753921574

path: .spaces[0].metrics.mi.mi_sei
old: 80.36121663649277
new: 43.04727259244317

path: .spaces[0].metrics.mi.mi_visual_studio
old: 63.21836649925735
new: 35.23043715743611

Code

namespace mozilla {

// We use a static var 'fuzzerRunner' defined in nsAppRunner.cpp.
// fuzzerRunner is initialized to nullptr but if this file is linked in,
// then fuzzerRunner will be set here indicating that
// we want to call into either LibFuzzer's main or the AFL entrypoint.
class _InitFuzzer {
 public:
  _InitFuzzer() { fuzzerRunner = new FuzzerRunner(); }
  void InitXPCOM() { mScopedXPCOM = new ScopedXPCOM("Fuzzer"); }
  void DeinitXPCOM() {
    if (mScopedXPCOM) delete mScopedXPCOM;
    mScopedXPCOM = nullptr;
  }

 private:
  ScopedXPCOM* mScopedXPCOM;
} InitLibFuzzer;

static void DeinitXPCOM() { InitLibFuzzer.DeinitXPCOM(); }

int FuzzerRunner::Run(int* argc, char*** argv) {
  /*
   * libFuzzer uses exit() calls in several places instead of returning,
   * so the destructor of ScopedXPCOM is not called in some cases.
   * For fuzzing, this does not make a difference, but in debug builds
   * when running a single testcase, this causes an assertion when destroying
   * global linked lists. For this reason, we allocate ScopedXPCOM on the heap
   * using the global InitLibFuzzer class, combined with an atexit call to
   * destroy the ScopedXPCOM instance again.
   */
  InitLibFuzzer.InitXPCOM();
  std::atexit(DeinitXPCOM);

  const char* fuzzerEnv = getenv("FUZZER");

  if (!fuzzerEnv) {
    fprintf(stderr,
            "Must specify fuzzing target in FUZZER environment variable\n");
    exit(1);
  }

  std::string moduleNameStr(fuzzerEnv);
  FuzzerFunctions funcs =
      FuzzerRegistry::getInstance().getModuleFunctions(moduleNameStr);
  FuzzerInitFunc initFunc = funcs.first;
  FuzzerTestingFunc testingFunc = funcs.second;
  if (initFunc) {
    int ret = initFunc(argc, argv);
    if (ret) {
      fprintf(stderr, "Fuzzing Interface: Error: Initialize callback failed\n");
      exit(1);
    }
  }

  if (!testingFunc) {
    fprintf(stderr, "Fuzzing Interface: Error: No testing callback found\n");
    exit(1);
  }

#ifdef LIBFUZZER
  int ret = mFuzzerDriver(argc, argv, testingFunc);
#else
  // For AFL, testingFunc points to the entry function we need.
  int ret = testingFunc(NULL, 0);
#endif

  InitLibFuzzer.DeinitXPCOM();
  return ret;
}

#ifdef LIBFUZZER
void FuzzerRunner::setParams(LibFuzzerDriver aDriver) {
  mFuzzerDriver = aDriver;
}
#endif

}  // namespace mozilla