summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerLoop.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-01-13 23:02:30 +0000
committerKostya Serebryany <kcc@google.com>2016-01-13 23:02:30 +0000
commitd50a3eedb4df2298de19e94189559b85af0f5094 (patch)
treeff45de1ce4a0dfce6dd9a211888d0413b86fb472 /llvm/lib/Fuzzer/FuzzerLoop.cpp
parent9913322327833d25ad52528167208e282155e439 (diff)
downloadbcm5719-llvm-d50a3eedb4df2298de19e94189559b85af0f5094.tar.gz
bcm5719-llvm-d50a3eedb4df2298de19e94189559b85af0f5094.zip
[libFuzzer] make sure we find buffer overflow in the input buffer. Previously, re-using the same vector object was hiding buffer overflows (unless we used annotated vector)
llvm-svn: 257701
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerLoop.cpp')
-rw-r--r--llvm/lib/Fuzzer/FuzzerLoop.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp
index 5237682ff24..ccc05c8b128 100644
--- a/llvm/lib/Fuzzer/FuzzerLoop.cpp
+++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp
@@ -11,6 +11,8 @@
#include "FuzzerInternal.h"
#include <algorithm>
+#include <cstring>
+#include <memory>
#if defined(__has_include)
# if __has_include(<sanitizer/coverage_interface.h>)
@@ -240,11 +242,12 @@ void Fuzzer::RunOneAndUpdateCorpus(Unit &U) {
}
void Fuzzer::ExecuteCallback(const Unit &U) {
- const uint8_t *Data = U.data();
- uint8_t EmptyData;
- if (!Data)
- Data = &EmptyData;
- int Res = USF.TargetFunction(Data, U.size());
+ // We copy the contents of Unit into a separate heap buffer
+ // so that we reliably find buffer overflows in it.
+ std::unique_ptr<uint8_t[]> Data(new uint8_t[U.size()]);
+ memcpy(Data.get(), U.data(), U.size());
+ AssignTaintLabels(Data.get(), U.size());
+ int Res = USF.TargetFunction(Data.get(), U.size());
(void)Res;
assert(Res == 0);
}
OpenPOWER on IntegriCloud