summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2015-09-02 19:08:08 +0000
committerKostya Serebryany <kcc@google.com>2015-09-02 19:08:08 +0000
commita9346c2e652e62d4de5e38e3402defd729d0286f (patch)
tree3a63104bdabfe2f7a757157feb45df7f464bc95a
parenta99ab1f5366100824241f410af9c32a434293f50 (diff)
downloadbcm5719-llvm-a9346c2e652e62d4de5e38e3402defd729d0286f.tar.gz
bcm5719-llvm-a9346c2e652e62d4de5e38e3402defd729d0286f.zip
[libFuzzer] honour -only_ascii=1 when reading the initial corpus. Also, remove ugly #ifdef
llvm-svn: 246689
-rw-r--r--llvm/lib/Fuzzer/FuzzerInternal.h1
-rw-r--r--llvm/lib/Fuzzer/FuzzerLoop.cpp8
-rw-r--r--llvm/lib/Fuzzer/FuzzerUtil.cpp6
3 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerInternal.h b/llvm/lib/Fuzzer/FuzzerInternal.h
index d9dc5283689..c44f0ea34d5 100644
--- a/llvm/lib/Fuzzer/FuzzerInternal.h
+++ b/llvm/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/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp
index 87ba0c0bbcd..dd81616b455 100644
--- a/llvm/lib/Fuzzer/FuzzerLoop.cpp
+++ b/llvm/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/llvm/lib/Fuzzer/FuzzerUtil.cpp b/llvm/lib/Fuzzer/FuzzerUtil.cpp
index e76adb37481..b04d76d316d 100644
--- a/llvm/lib/Fuzzer/FuzzerUtil.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud