header_parser_fuzzer.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. uint8_t selector = data[0];
  8. const char *payload = reinterpret_cast<const char *>(data + 1);
  9. size_t payload_size = size - 1;
  10. std::string input(payload, payload_size);
  11. switch (selector % 7) {
  12. case 0: {
  13. // parse_range_header
  14. httplib::Ranges ranges;
  15. httplib::detail::parse_range_header(input, ranges);
  16. break;
  17. }
  18. case 1: {
  19. // parse_accept_header
  20. std::vector<std::string> content_types;
  21. httplib::detail::parse_accept_header(input, content_types);
  22. break;
  23. }
  24. case 2: {
  25. // extract_media_type with params
  26. std::map<std::string, std::string> params;
  27. httplib::detail::extract_media_type(input, &params);
  28. break;
  29. }
  30. case 3: {
  31. // parse_multipart_boundary
  32. std::string boundary;
  33. httplib::detail::parse_multipart_boundary(input, boundary);
  34. break;
  35. }
  36. case 4: {
  37. // parse_disposition_params
  38. httplib::Params params;
  39. httplib::detail::parse_disposition_params(input, params);
  40. break;
  41. }
  42. case 5: {
  43. // parse_http_date
  44. httplib::detail::parse_http_date(input);
  45. break;
  46. }
  47. case 6: {
  48. // can_compress_content_type
  49. httplib::detail::can_compress_content_type(input);
  50. break;
  51. }
  52. }
  53. return 0;
  54. }