1# HG changeset patch 2# User Christian Holler <choller@mozilla.com> 3# Date 1596126768 -7200 4# Thu Jul 30 18:32:48 2020 +0200 5# Node ID 64e7d096fa77a62b71a306b2c5383b8f75ac4945 6# Parent ea198a0331a6db043cb5978512226977514104db 7[libFuzzer] Allow custom mutators to fail 8 9diff --git a/tools/fuzzing/libfuzzer/FuzzerLoop.cpp b/tools/fuzzing/libfuzzer/FuzzerLoop.cpp 10--- a/tools/fuzzing/libfuzzer/FuzzerLoop.cpp 11+++ b/tools/fuzzing/libfuzzer/FuzzerLoop.cpp 12@@ -690,16 +690,20 @@ void Fuzzer::MutateAndTestOne() { 13 if (II.HasFocusFunction && !II.DataFlowTraceForFocusFunction.empty() && 14 Size <= CurrentMaxMutationLen) 15 NewSize = MD.MutateWithMask(CurrentUnitData, Size, Size, 16 II.DataFlowTraceForFocusFunction); 17 18 // If MutateWithMask either failed or wasn't called, call default Mutate. 19 if (!NewSize) 20 NewSize = MD.Mutate(CurrentUnitData, Size, CurrentMaxMutationLen); 21+ 22+ if (!NewSize) 23+ continue; 24+ 25 assert(NewSize > 0 && "Mutator returned empty unit"); 26 assert(NewSize <= CurrentMaxMutationLen && "Mutator return oversized unit"); 27 Size = NewSize; 28 II.NumExecutedMutations++; 29 Corpus.IncrementNumExecutedMutations(); 30 31 bool FoundUniqFeatures = false; 32 bool NewCov = RunOne(CurrentUnitData, Size, /*MayDeleteFile=*/true, &II, 33@@ -850,17 +854,19 @@ void Fuzzer::Loop(Vector<SizedFile> &Cor 34 void Fuzzer::MinimizeCrashLoop(const Unit &U) { 35 if (U.size() <= 1) 36 return; 37 while (!TimedOut() && TotalNumberOfRuns < Options.MaxNumberOfRuns) { 38 MD.StartMutationSequence(); 39 memcpy(CurrentUnitData, U.data(), U.size()); 40 for (int i = 0; i < Options.MutateDepth; i++) { 41 size_t NewSize = MD.Mutate(CurrentUnitData, U.size(), MaxMutationLen); 42- assert(NewSize > 0 && NewSize <= MaxMutationLen); 43+ assert(NewSize <= MaxMutationLen); 44+ if (!NewSize) 45+ continue; 46 ExecuteCallback(CurrentUnitData, NewSize); 47 PrintPulseAndReportSlowInput(CurrentUnitData, NewSize); 48 TryDetectingAMemoryLeak(CurrentUnitData, NewSize, 49 /*DuringInitialCorpusExecution*/ false); 50 } 51 } 52 } 53 54