// Copyright (c) 2020-now by the Zeek Project. See LICENSE for details. #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef SPICY_FUZZ_PARSER #error "SPICY_FUZZ_PARSER needs to be defined" #endif extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) { static const spicy::rt::Parser* parser = nullptr; if ( ! parser ) { hilti::rt::init(); spicy::rt::init(); for ( auto* p : spicy::rt::parsers() ) { parser = p; if ( p->name == SPICY_FUZZ_PARSER ) break; } } assert(parser); hilti::rt::ValueReference stream; stream->append(reinterpret_cast(Data), Size); hilti::rt::ValueReference pu; try { if ( parser->parse1 ) parser->parse1(stream, {}, {}); else if ( parser->parse3 ) parser->parse3(pu, stream, {}, {}); } catch ( ... ) { } return 0; // Non-zero return values are reserved for future use. } extern "C" int LLVMFuzzerRunDriver(int* argc, char*** argv, int (*UserCb)(const uint8_t* Data, size_t Size)); // We provide our own `main` to avoid linking to hilti-rt's weak `main` symbol. int main(int argc, char** argv) { LLVMFuzzerRunDriver(&argc, &argv, LLVMFuzzerTestOneInput); }