diff options
author | Kostya Serebryany <kcc@google.com> | 2016-01-13 23:02:30 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-01-13 23:02:30 +0000 |
commit | d50a3eedb4df2298de19e94189559b85af0f5094 (patch) | |
tree | ff45de1ce4a0dfce6dd9a211888d0413b86fb472 /llvm/lib/Fuzzer/FuzzerLoop.cpp | |
parent | 9913322327833d25ad52528167208e282155e439 (diff) | |
download | bcm5719-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.cpp | 13 |
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); } |