Index: tools/clang-fuzzer/CMakeLists.txt =================================================================== --- tools/clang-fuzzer/CMakeLists.txt +++ tools/clang-fuzzer/CMakeLists.txt @@ -14,6 +14,7 @@ ClangFuzzer.cpp DummyClangFuzzer.cpp ExampleClangProtoFuzzer.cpp + FuzzerInitialize.cpp ) if(CLANG_ENABLE_PROTO_FUZZER) @@ -44,6 +45,7 @@ add_clang_executable(clang-proto-fuzzer ${DUMMY_MAIN} ExampleClangProtoFuzzer.cpp + FuzzerInitialize.cpp ) target_link_libraries(clang-proto-fuzzer Index: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp =================================================================== --- tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp +++ tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp @@ -18,12 +18,15 @@ #include "handle-cxx/handle_cxx.h" #include "proto-to-cxx/proto_to_cxx.h" +#include "FuzzerInitialize.h" + #include "src/libfuzzer/libfuzzer_macro.h" #include using namespace clang_fuzzer; +/* static std::vector CLArgs; extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { @@ -37,8 +40,9 @@ } return 0; } +*/ -DEFINE_BINARY_PROTO_FUZZER(const Function& input) { +DEFINE_PROTO_FUZZER(const Function& input) { auto S = FunctionToString(input); HandleCXX(S, CLArgs); } Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h =================================================================== --- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h +++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h @@ -19,4 +19,5 @@ class Function; std::string FunctionToString(const Function &input); std::string ProtoToCxx(const uint8_t *data, size_t size); +std::string ProtoStringToCxx(const std::string& data); } Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp =================================================================== --- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp +++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp @@ -14,6 +14,10 @@ #include "proto_to_cxx.h" #include "cxx_proto.pb.h" +// The following is needed to convert protos in human-readable form +#include + + #include #include @@ -95,7 +99,13 @@ std::string ProtoToCxx(const uint8_t *data, size_t size) { Function message; if (!message.ParsePartialFromArray(data, size)) - return "#error invalid proto\n"; + return "#error invalid proto, may not be binary encoded\n"; + return FunctionToString(message); +} +std::string ProtoStringToCxx(const std::string& data) { + Function message; + if (!google::protobuf::TextFormat::ParseFromString(data, &message)) + return "#error invalid proto, may not be string encoded\n"; return FunctionToString(message); } Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx_main.cpp =================================================================== --- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx_main.cpp +++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx_main.cpp @@ -23,8 +23,9 @@ std::string str((std::istreambuf_iterator(in)), std::istreambuf_iterator()); std::cout << "// " << argv[i] << std::endl; - std::cout << clang_fuzzer::ProtoToCxx( - reinterpret_cast(str.data()), str.size()); + //std::cout << clang_fuzzer::ProtoToCxx( + // reinterpret_cast(str.data()), str.size()); + std::cout << clang_fuzzer::ProtoStringToCxx(str); } }