File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -17,3 +17,14 @@ if(UNIX)
17
17
endif (LINUX )
18
18
19
19
endif (UNIX )
20
+
21
+ if (FUZZ )
22
+ add_executable (urltest-fuzz urltest-fuzz.cpp )
23
+ # TODO add_executable(pcm-sensor-server-fuzz pcm-sensor-server-fuzz.cpp)
24
+ set (FUZZER_OPTIONS "-fsanitize=fuzzer,address -fprofile-instr-generate -fcoverage-mapping" )
25
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUZZER_OPTIONS} " )
26
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUZZER_OPTIONS} " )
27
+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FUZZER_OPTIONS} " )
28
+ target_link_libraries (urltest-fuzz Threads::Threads PCM_STATIC )
29
+ # TODO: target_link_libraries(pcm-sensor-server-fuzz Threads::Threads PCM_STATIC)
30
+ endif ()
Original file line number Diff line number Diff line change
1
+
2
+ CC=` which clang` CXX=` which clang++` cmake .. -DCMAKE_BUILD_TYPE=Debug -DFUZZ=1 && mkdir corpus &&
3
+ make urltest-fuzz &&
4
+ bin/tests/urltest-fuzz -max_total_time=30 corpus &&
5
+ llvm-profdata merge -sparse default.profraw -o default.profdata &&
6
+ llvm-cov report --summary-only ./bin/tests/urltest-fuzz -instr-profile=default.profdata
7
+
Original file line number Diff line number Diff line change
1
+ #define UNIT_TEST 1
2
+
3
+ #include " ../src/pcm-sensor-server.cpp"
4
+
5
+ #undef UNIT_TEST
6
+
7
+
8
+ extern " C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
9
+ {
10
+ try
11
+ {
12
+ std::string buf (reinterpret_cast <const char *>(data), size);
13
+ buf.push_back (' \0 ' );
14
+ URL x = URL::parse (buf.c_str ());
15
+ }
16
+ catch (std::runtime_error & )
17
+ {
18
+ // catch recognized malformed input (thrown as runtime_error in the URL::parse)
19
+ // do not catch any other errors or exceptions to let them be reported
20
+ // by libFuzzer
21
+ }
22
+
23
+ return 0 ;
24
+ }
25
+
You can’t perform that action at this time.
0 commit comments