From d50a3eedb4df2298de19e94189559b85af0f5094 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 13 Jan 2016 23:02:30 +0000 Subject: [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 --- llvm/lib/Fuzzer/FuzzerLoop.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Fuzzer/FuzzerLoop.cpp') 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 +#include +#include #if defined(__has_include) # if __has_include() @@ -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 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); } -- cgit v1.2.3