2017-08-09 04:15:04 +08:00
|
|
|
//===-- ExampleClangProtoFuzzer.cpp - Fuzz Clang --------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-09 09:00:01 +08:00
|
|
|
/// This file implements a function that runs Clang on a single
|
2017-08-09 04:15:04 +08:00
|
|
|
/// input and uses libprotobuf-mutator to find new inputs. This function is
|
|
|
|
/// then linked into the Fuzzer library.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "cxx_proto.pb.h"
|
|
|
|
#include "handle-cxx/handle_cxx.h"
|
|
|
|
#include "proto-to-cxx/proto_to_cxx.h"
|
|
|
|
|
|
|
|
#include "src/libfuzzer/libfuzzer_macro.h"
|
|
|
|
|
2017-08-19 02:34:39 +08:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-08-09 04:15:04 +08:00
|
|
|
using namespace clang_fuzzer;
|
|
|
|
|
2017-08-19 02:34:39 +08:00
|
|
|
static std::vector<const char *> CLArgs;
|
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
|
|
|
|
CLArgs.push_back("-O2");
|
|
|
|
for (int I = 1; I < *argc; I++) {
|
|
|
|
if (strcmp((*argv)[I], "-ignore_remaining_args=1") == 0) {
|
|
|
|
for (I++; I < *argc; I++)
|
|
|
|
CLArgs.push_back((*argv)[I]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-09 04:15:04 +08:00
|
|
|
DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
|
|
|
|
auto S = FunctionToString(input);
|
2017-08-19 02:34:39 +08:00
|
|
|
HandleCXX(S, CLArgs);
|
2017-08-09 04:15:04 +08:00
|
|
|
}
|