summaryrefslogtreecommitdiff
path: root/lib/fuzzer/FuzzerCorpus.h
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2018-06-07 01:40:20 +0000
committerKostya Serebryany <kcc@google.com>2018-06-07 01:40:20 +0000
commitce30747f4d0de2e549ebbde21d5ceddcbac27e75 (patch)
treef2f673214af79480ee041bed582d7ed6c03a77a2 /lib/fuzzer/FuzzerCorpus.h
parentf46892192068bf16984d429dbeb4123c12c47eca (diff)
[libFuzzer] make the corpus elements aware of their data flow traces
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@334158 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/fuzzer/FuzzerCorpus.h')
-rw-r--r--lib/fuzzer/FuzzerCorpus.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/fuzzer/FuzzerCorpus.h b/lib/fuzzer/FuzzerCorpus.h
index b4ba64b4b..c1603e1ad 100644
--- a/lib/fuzzer/FuzzerCorpus.h
+++ b/lib/fuzzer/FuzzerCorpus.h
@@ -12,6 +12,7 @@
#ifndef LLVM_FUZZER_CORPUS
#define LLVM_FUZZER_CORPUS
+#include "FuzzerDataFlowTrace.h"
#include "FuzzerDefs.h"
#include "FuzzerIO.h"
#include "FuzzerRandom.h"
@@ -37,6 +38,7 @@ struct InputInfo {
bool Reduced = false;
bool HasFocusFunction = false;
Vector<uint32_t> UniqFeatureSet;
+ Vector<bool> DataFlowTraceForFocusFunction;
};
class InputCorpus {
@@ -76,10 +78,17 @@ class InputCorpus {
});
}
+ size_t NumInputsWithDataFlowTrace() {
+ return std::count_if(Inputs.begin(), Inputs.end(), [](const InputInfo *II) {
+ return !II->DataFlowTraceForFocusFunction.empty();
+ });
+ }
+
bool empty() const { return Inputs.empty(); }
const Unit &operator[] (size_t Idx) const { return Inputs[Idx]->U; }
void AddToCorpus(const Unit &U, size_t NumFeatures, bool MayDeleteFile,
- bool HasFocusFunction, const Vector<uint32_t> &FeatureSet) {
+ bool HasFocusFunction, const Vector<uint32_t> &FeatureSet,
+ const DataFlowTrace &DFT) {
assert(!U.empty());
if (FeatureDebug)
Printf("ADD_TO_CORPUS %zd NF %zd\n", Inputs.size(), NumFeatures);
@@ -92,7 +101,11 @@ class InputCorpus {
II.HasFocusFunction = HasFocusFunction;
std::sort(II.UniqFeatureSet.begin(), II.UniqFeatureSet.end());
ComputeSHA1(U.data(), U.size(), II.Sha1);
- Hashes.insert(Sha1ToString(II.Sha1));
+ auto Sha1Str = Sha1ToString(II.Sha1);
+ Hashes.insert(Sha1Str);
+ if (HasFocusFunction)
+ if (auto V = DFT.Get(Sha1Str))
+ II.DataFlowTraceForFocusFunction = *V;
UpdateCorpusDistribution();
PrintCorpus();
// ValidateFeatureSet();