aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Fuzzer/test/BufferOverflowOnInput.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/test/BufferOverflowOnInput.cpp
parent9913322327833d25ad52528167208e282155e439 (diff)
downloadllvm-d50a3eedb4df2298de19e94189559b85af0f5094.zip
llvm-d50a3eedb4df2298de19e94189559b85af0f5094.tar.gz
llvm-d50a3eedb4df2298de19e94189559b85af0f5094.tar.bz2
[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/test/BufferOverflowOnInput.cpp')
-rw-r--r--llvm/lib/Fuzzer/test/BufferOverflowOnInput.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/BufferOverflowOnInput.cpp b/llvm/lib/Fuzzer/test/BufferOverflowOnInput.cpp
new file mode 100644
index 0000000..9bebd84
--- /dev/null
+++ b/llvm/lib/Fuzzer/test/BufferOverflowOnInput.cpp
@@ -0,0 +1,20 @@
+// Simple test for a fuzzer. The fuzzer must find the string "Hi!".
+#include <assert.h>
+#include <cstdint>
+#include <cstdlib>
+#include <cstddef>
+#include <iostream>
+
+static volatile bool SeedLargeBuffer;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ assert(Data);
+ if (Size >= 4)
+ SeedLargeBuffer = true;
+ if (Size == 3 && SeedLargeBuffer && Data[3]) {
+ std::cout << "Woops, reading Data[3] w/o crashing\n";
+ exit(1);
+ }
+ return 0;
+}
+