[fuzzer] Add support for token-based fuzzing (e.g. for C++). Allow string flags.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233745 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kostya Serebryany
2015-03-31 20:13:20 +00:00
parent 9df365e44e
commit 3399e1fd73
10 changed files with 422 additions and 58 deletions

View File

@@ -6,6 +6,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "${LIBFUZZER_FLAGS_BASE} -O0 -fsanitize-coverage=4")
set(Tests
CounterTest
CxxTokensTest
FourIndependentBranchesTest
FullCoverageSetTest
InfiniteTest

View File

@@ -0,0 +1,24 @@
// Simple test for a fuzzer. The fuzzer must find a sequence of C++ tokens.
#include <cstdint>
#include <cstdlib>
#include <cstddef>
#include <cstring>
#include <iostream>
static void Found() {
std::cout << "Found the target, exiting\n";
exit(1);
}
extern "C" void TestOneInput(const uint8_t *Data, size_t Size) {
// looking for "thread_local unsigned A;"
if (Size < 24) return;
if (0 == memcmp(&Data[0], "thread_local", 12))
if (Data[12] == ' ')
if (0 == memcmp(&Data[13], "unsigned", 8))
if (Data[21] == ' ')
if (Data[22] == 'A')
if (Data[23] == ';')
Found();
}

View File

@@ -23,3 +23,6 @@ CounterTest: BINGO
RUN: not ./LLVMFuzzer-DFSanSimpleCmpTest -seed=1 -timeout=15 2>&1 | FileCheck %s --check-prefix=DFSanSimpleCmpTest
DFSanSimpleCmpTest: Found the target:
RUN: not ./LLVMFuzzer-CxxTokensTest -seed=1 -timeout=15 -tokens=%S/../cxx_fuzzer_tokens.txt 2>&1 | FileCheck %s --check-prefix=CxxTokensTest
CxxTokensTest: Found the target, exiting