forked from weaselab/weaseljson
Add a fallback fuzz binary if libfuzzer not available
This commit is contained in:
@@ -173,6 +173,11 @@ if(HAS_LIB_FUZZER)
|
|||||||
target_link_libraries(fuzz PRIVATE simdjson)
|
target_link_libraries(fuzz PRIVATE simdjson)
|
||||||
target_compile_options(fuzz PRIVATE -fsanitize=fuzzer ${TEST_FLAGS})
|
target_compile_options(fuzz PRIVATE -fsanitize=fuzzer ${TEST_FLAGS})
|
||||||
target_link_options(fuzz PRIVATE -fsanitize=fuzzer)
|
target_link_options(fuzz PRIVATE -fsanitize=fuzzer)
|
||||||
|
else()
|
||||||
|
add_executable(fuzz src/fuzz.cpp src/lib.cpp src/fuzz_driver.cpp)
|
||||||
|
target_include_directories(fuzz PRIVATE include)
|
||||||
|
target_link_libraries(fuzz PRIVATE simdjson)
|
||||||
|
target_compile_options(fuzz PRIVATE ${TEST_FLAGS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(validate src/validate.cpp)
|
add_executable(validate src/validate.cpp)
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
auto doTest = [&]() {
|
||||||
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
std::ifstream t(argv[i], std::ios::binary);
|
||||||
|
std::stringstream buffer;
|
||||||
|
buffer << t.rdbuf();
|
||||||
|
auto str = buffer.str();
|
||||||
|
LLVMFuzzerTestOneInput((const uint8_t *)str.data(), str.size());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user