From: Kostya Serebryany Date: Wed, 2 Sep 2015 19:08:08 +0000 (+0000) Subject: [libFuzzer] honour -only_ascii=1 when reading the initial corpus. Also, remove ugly... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=580504f120cad32f8402f0efbca37650e3f19168;hp=1cded9afe4df04564b38d63556fa4f7c53c52e2b [libFuzzer] honour -only_ascii=1 when reading the initial corpus. Also, remove ugly #ifdef git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246689 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Fuzzer/FuzzerInternal.h b/lib/Fuzzer/FuzzerInternal.h index d9dc5283689..c44f0ea34d5 100644 --- a/lib/Fuzzer/FuzzerInternal.h +++ b/lib/Fuzzer/FuzzerInternal.h @@ -53,6 +53,7 @@ void ComputeSHA1(const uint8_t *Data, size_t Len, uint8_t *Out); // Changes U to contain only ASCII (isprint+isspace) characters. // Returns true iff U has been changed. bool ToASCII(Unit &U); +bool IsASCII(const Unit &U); int NumberOfCpuCores(); diff --git a/lib/Fuzzer/FuzzerLoop.cpp b/lib/Fuzzer/FuzzerLoop.cpp index 87ba0c0bbcd..dd81616b455 100644 --- a/lib/Fuzzer/FuzzerLoop.cpp +++ b/lib/Fuzzer/FuzzerLoop.cpp @@ -136,6 +136,8 @@ void Fuzzer::ShuffleAndMinimize() { U.clear(); size_t Last = std::min(First + Options.MaxLen, C.size()); U.insert(U.begin(), C.begin() + First, C.begin() + Last); + if (Options.OnlyASCII) + ToASCII(U); size_t NewCoverage = RunOne(U); if (NewCoverage) { MaxCov = NewCoverage; @@ -256,11 +258,7 @@ void Fuzzer::WriteToOutputCorpus(const Unit &U) { WriteToFile(U, Path); if (Options.Verbosity >= 2) Printf("Written to %s\n", Path.c_str()); -#ifdef DEBUG - if (Options.OnlyASCII) - for (auto X : U) - assert(isprint(X) || isspace(X)); -#endif + assert(!Options.OnlyASCII || IsASCII(U)); } void Fuzzer::WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix) { diff --git a/lib/Fuzzer/FuzzerUtil.cpp b/lib/Fuzzer/FuzzerUtil.cpp index e76adb37481..b04d76d316d 100644 --- a/lib/Fuzzer/FuzzerUtil.cpp +++ b/lib/Fuzzer/FuzzerUtil.cpp @@ -86,4 +86,10 @@ bool ToASCII(Unit &U) { return Changed; } +bool IsASCII(const Unit &U) { + for (auto X : U) + if (!(isprint(X) || isspace(X))) return false; + return true; +} + } // namespace fuzzer