/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.59k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
8 | 4.59k | if (size < 2) return 0; |
9 | | |
10 | | // Use first byte to select which parsing function to exercise |
11 | 4.59k | uint8_t selector = data[0]; |
12 | 4.59k | const char *payload = reinterpret_cast<const char *>(data + 1); |
13 | 4.59k | size_t payload_size = size - 1; |
14 | 4.59k | std::string input(payload, payload_size); |
15 | | |
16 | 4.59k | switch (selector % 6) { |
17 | 806 | case 0: { |
18 | | // parse_query_text |
19 | 806 | httplib::Params params; |
20 | 806 | httplib::detail::parse_query_text(payload, payload_size, params); |
21 | 806 | break; |
22 | 0 | } |
23 | 658 | case 1: { |
24 | | // decode_query_component |
25 | 658 | httplib::decode_query_component(input, true); |
26 | 658 | httplib::decode_query_component(input, false); |
27 | 658 | break; |
28 | 0 | } |
29 | 1.21k | case 2: { |
30 | | // decode_path_component |
31 | 1.21k | httplib::decode_path_component(input); |
32 | 1.21k | break; |
33 | 0 | } |
34 | 465 | case 3: { |
35 | | // encode_query_component |
36 | 465 | httplib::encode_query_component(input); |
37 | 465 | break; |
38 | 0 | } |
39 | 538 | case 4: { |
40 | | // normalize_query_string |
41 | 538 | httplib::detail::normalize_query_string(input); |
42 | 538 | break; |
43 | 0 | } |
44 | 911 | case 5: { |
45 | | // is_valid_path |
46 | 911 | httplib::detail::is_valid_path(input); |
47 | 911 | break; |
48 | 0 | } |
49 | 4.59k | } |
50 | | |
51 | 4.59k | return 0; |
52 | 4.59k | } |