From 3f6c1627f71364764993e5eec8467abbc3217314 Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Tue, 17 Oct 2017 17:43:34 +0000 Subject: [PATCH] [llvm-special-case-list-fuzzer] Add fuzz target. Summary: Create a fuzzer for sanitizer blacklists. Patch by: hctim Reviewers: morehouse Reviewed By: morehouse Subscribers: llvm-commits, mgorny, kcc Differential Revision: https://review.llvm.org/D38981 llvm-svn: 316014 --- .../llvm-special-case-list-fuzzer/CMakeLists.txt | 8 +++++++ .../DummySpecialCaseListFuzzer.cpp | 19 ++++++++++++++++ .../special-case-list-fuzzer.cpp | 26 ++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 llvm/tools/llvm-special-case-list-fuzzer/CMakeLists.txt create mode 100644 llvm/tools/llvm-special-case-list-fuzzer/DummySpecialCaseListFuzzer.cpp create mode 100644 llvm/tools/llvm-special-case-list-fuzzer/special-case-list-fuzzer.cpp diff --git a/llvm/tools/llvm-special-case-list-fuzzer/CMakeLists.txt b/llvm/tools/llvm-special-case-list-fuzzer/CMakeLists.txt new file mode 100644 index 0000000..f4ebf7a --- /dev/null +++ b/llvm/tools/llvm-special-case-list-fuzzer/CMakeLists.txt @@ -0,0 +1,8 @@ +set(LLVM_LINK_COMPONENTS + Support + FuzzMutate +) + +add_llvm_fuzzer(llvm-special-case-list-fuzzer + special-case-list-fuzzer.cpp + DUMMY_MAIN DummySpecialCaseListFuzzer.cpp) diff --git a/llvm/tools/llvm-special-case-list-fuzzer/DummySpecialCaseListFuzzer.cpp b/llvm/tools/llvm-special-case-list-fuzzer/DummySpecialCaseListFuzzer.cpp new file mode 100644 index 0000000..e447419 --- /dev/null +++ b/llvm/tools/llvm-special-case-list-fuzzer/DummySpecialCaseListFuzzer.cpp @@ -0,0 +1,19 @@ +//===--- DummySpecialCaseListFuzzer.cpp -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Implementation of main so we can build and test without linking libFuzzer. +// +//===----------------------------------------------------------------------===// + +#include "llvm/FuzzMutate/FuzzerCLI.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); +int main(int argc, char *argv[]) { + return llvm::runFuzzerOnInputs(argc, argv, LLVMFuzzerTestOneInput); +} diff --git a/llvm/tools/llvm-special-case-list-fuzzer/special-case-list-fuzzer.cpp b/llvm/tools/llvm-special-case-list-fuzzer/special-case-list-fuzzer.cpp new file mode 100644 index 0000000..e7e310b --- /dev/null +++ b/llvm/tools/llvm-special-case-list-fuzzer/special-case-list-fuzzer.cpp @@ -0,0 +1,26 @@ +//===--- special-case-list-fuzzer.cpp - Fuzzer for special case lists -----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SpecialCaseList.h" + +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + std::unique_ptr Buf = llvm::MemoryBuffer::getMemBuffer( + llvm::StringRef(reinterpret_cast(Data), Size), "", false); + + if (!Buf) + return 0; + + std::string Error; + llvm::SpecialCaseList::create(Buf.get(), Error); + + return 0; +} -- 2.7.4