/src/cpp-httplib/test/fuzzing/url_parser_fuzzer.cc
Line | Count | Source |
1 | | #include <cstdint> |
2 | | #include <cstring> |
3 | | #include <string> |
4 | | |
5 | | #include <httplib.h> |
6 | | |
7 | 4.68k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
8 | 4.68k | if (size < 2) return 0; |
9 | | |
10 | | // Use first byte to select which parsing function to exercise |
11 | 4.68k | uint8_t selector = data[0]; |
12 | 4.68k | const char *payload = reinterpret_cast<const char *>(data + 1); |
13 | 4.68k | size_t payload_size = size - 1; |
14 | 4.68k | std::string input(payload, payload_size); |
15 | | |
16 | 4.68k | switch (selector % 6) { |
17 | 772 | case 0: { |
18 | | // parse_query_text |
19 | 772 | httplib::Params params; |
20 | 772 | httplib::detail::parse_query_text(payload, payload_size, params); |
21 | 772 | break; |
22 | 0 | } |
23 | 703 | case 1: { |
24 | | // decode_query_component |
25 | 703 | httplib::decode_query_component(input, true); |
26 | 703 | httplib::decode_query_component(input, false); |
27 | 703 | break; |
28 | 0 | } |
29 | 1.11k | case 2: { |
30 | | // decode_path_component |
31 | 1.11k | httplib::decode_path_component(input); |
32 | 1.11k | break; |
33 | 0 | } |
34 | 430 | case 3: { |
35 | | // encode_query_component |
36 | 430 | httplib::encode_query_component(input); |
37 | 430 | break; |
38 | 0 | } |
39 | 589 | case 4: { |
40 | | // normalize_query_string |
41 | 589 | httplib::detail::normalize_query_string(input); |
42 | 589 | break; |
43 | 0 | } |
44 | 1.07k | case 5: { |
45 | | // is_valid_path |
46 | 1.07k | httplib::detail::is_valid_path(input); |
47 | 1.07k | break; |
48 | 0 | } |
49 | 4.68k | } |
50 | | |
51 | 4.68k | return 0; |
52 | 4.68k | } |