]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] add a test with two different bugs
authorKostya Serebryany <kcc@google.com>
Fri, 17 Mar 2017 01:33:16 +0000 (01:33 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 17 Mar 2017 01:33:16 +0000 (01:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298030 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/test/CMakeLists.txt
lib/Fuzzer/test/TwoDifferentBugsTest.cpp [new file with mode: 0644]

index ab4ae92c1f4df6cdb4286ff29f27c2bf3aea344f..2a31a801f9de0758ab25f4adccfe839b251ec5b4 100644 (file)
@@ -128,6 +128,7 @@ set(Tests
   TimeoutTest
   TimeoutEmptyTest
   TraceMallocTest
+  TwoDifferentBugsTest
   )
 
 if(APPLE OR MSVC)
diff --git a/lib/Fuzzer/test/TwoDifferentBugsTest.cpp b/lib/Fuzzer/test/TwoDifferentBugsTest.cpp
new file mode 100644 (file)
index 0000000..42c0d19
--- /dev/null
@@ -0,0 +1,22 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+// Simple test for a fuzzer. This test may trigger two different bugs.
+#include <cstdint>
+#include <cstdlib>
+#include <cstddef>
+#include <iostream>
+
+static volatile int *Null = 0;
+
+void Foo() { Null[1] = 0; }
+void Bar() { Null[2] = 0; }
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  if (Size < 10 && Data[0] == 'H')
+    Foo();
+  if (Size >= 10 && Data[0] == 'H')
+    Bar();
+  return 0;
+}
+