llvm-fuzzer-testcase.c++ (996B)
1 #include "test-util.h" 2 #include <kj/main.h> 3 #include "serialize.h" 4 #include <capnp/test.capnp.h> 5 #include <unistd.h> 6 7 /* This is the entry point of a fuzz target to be used with libFuzzer 8 * or another fuzz driver. 9 * Such a fuzz driver is used by the autotools target capnp-llvm-fuzzer-testcase 10 * when the environment variable LIB_FUZZING_ENGINE is defined 11 * for instance LIB_FUZZING_ENGINE=-fsanitize=fuzzer for libFuzzer 12 */ 13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) { 14 kj::ArrayPtr<const uint8_t> array(Data, Size); 15 kj::ArrayInputStream ais(array); 16 17 KJ_IF_MAYBE(e, kj::runCatchingExceptions([&]() { 18 capnp::InputStreamMessageReader reader(ais); 19 capnp::_::checkTestMessage(reader.getRoot<capnp::_::TestAllTypes>()); 20 capnp::_::checkDynamicTestMessage(reader.getRoot<capnp::DynamicStruct>(capnp::Schema::from<capnp::_::TestAllTypes>())); 21 kj::str(reader.getRoot<capnp::_::TestAllTypes>()); 22 })) { 23 KJ_LOG(ERROR, "threw"); 24 } 25 return 0; 26 }