summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/test
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2017-05-09 01:17:29 +0000
committerKostya Serebryany <kcc@google.com>2017-05-09 01:17:29 +0000
commitfe4ed9bd854d1230723568a8cc6289bf9da7fff7 (patch)
treec9d6415d69ed700008c4c4783eb3cb80048411f4 /llvm/lib/Fuzzer/test
parent9f29914d4018c0c8ef2b7b7bceffb0d07483e89c (diff)
downloadbcm5719-llvm-fe4ed9bd854d1230723568a8cc6289bf9da7fff7.tar.gz
bcm5719-llvm-fe4ed9bd854d1230723568a8cc6289bf9da7fff7.zip
[libFuzzer] make sure the input data is not overwritten in the fuzz target (if it is -- report an error)
llvm-svn: 302494
Diffstat (limited to 'llvm/lib/Fuzzer/test')
-rw-r--r--llvm/lib/Fuzzer/test/CMakeLists.txt1
-rw-r--r--llvm/lib/Fuzzer/test/OverwriteInputTest.cpp13
-rw-r--r--llvm/lib/Fuzzer/test/overwrite-input.test2
3 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/CMakeLists.txt b/llvm/lib/Fuzzer/test/CMakeLists.txt
index cd049d3f03d..b39938a705f 100644
--- a/llvm/lib/Fuzzer/test/CMakeLists.txt
+++ b/llvm/lib/Fuzzer/test/CMakeLists.txt
@@ -104,6 +104,7 @@ set(Tests
OneHugeAllocTest
OutOfMemoryTest
OutOfMemorySingleLargeMallocTest
+ OverwriteInputTest
RepeatedMemcmp
RepeatedBytesTest
SimpleCmpTest
diff --git a/llvm/lib/Fuzzer/test/OverwriteInputTest.cpp b/llvm/lib/Fuzzer/test/OverwriteInputTest.cpp
new file mode 100644
index 00000000000..e688682346a
--- /dev/null
+++ b/llvm/lib/Fuzzer/test/OverwriteInputTest.cpp
@@ -0,0 +1,13 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+// Simple test for a fuzzer. Make sure we abort if Data is overwritten.
+#include <cstdint>
+#include <iostream>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size)
+ *const_cast<uint8_t*>(Data) = 1;
+ return 0;
+}
+
diff --git a/llvm/lib/Fuzzer/test/overwrite-input.test b/llvm/lib/Fuzzer/test/overwrite-input.test
new file mode 100644
index 00000000000..81c27909e8d
--- /dev/null
+++ b/llvm/lib/Fuzzer/test/overwrite-input.test
@@ -0,0 +1,2 @@
+RUN: not LLVMFuzzer-OverwriteInputTest 2>&1 | FileCheck %s
+CHECK: ERROR: libFuzzer: fuzz target overwrites it's const input
OpenPOWER on IntegriCloud