url_parser_fuzzer.cc 1.1 KB

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