mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-04-12 19:58:29 +00:00
Add two new fuzzers (#2412)
The goal is to increase code coverage by way of OSS-Fuzz. A recent code coverage report is available at https://storage.googleapis.com/oss-fuzz-coverage/cpp-httplib/reports/20260326/linux/report.html Signed-off-by: David Korczynski <david@adalogics.com>
This commit is contained in:
52
test/fuzzing/url_parser_fuzzer.cc
Normal file
52
test/fuzzing/url_parser_fuzzer.cc
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (size < 2) return 0;
|
||||
|
||||
// Use first byte to select which parsing function to exercise
|
||||
uint8_t selector = data[0];
|
||||
const char *payload = reinterpret_cast<const char *>(data + 1);
|
||||
size_t payload_size = size - 1;
|
||||
std::string input(payload, payload_size);
|
||||
|
||||
switch (selector % 6) {
|
||||
case 0: {
|
||||
// parse_query_text
|
||||
httplib::Params params;
|
||||
httplib::detail::parse_query_text(payload, payload_size, params);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
// decode_query_component
|
||||
httplib::decode_query_component(input, true);
|
||||
httplib::decode_query_component(input, false);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
// decode_path_component
|
||||
httplib::decode_path_component(input);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
// encode_query_component
|
||||
httplib::encode_query_component(input);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
// normalize_query_string
|
||||
httplib::detail::normalize_query_string(input);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
// is_valid_path
|
||||
httplib::detail::is_valid_path(input);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user