fuzz.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "mongoose.h"
  2. #ifdef __cplusplus
  3. extern "C" int LLVMFuzzerTestOneInput(const uint8_t *, size_t);
  4. #else
  5. int LLVMFuzzerTestOneInput(const uint8_t *, size_t);
  6. #endif
  7. int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  8. mg_log_set(MG_LL_NONE);
  9. struct mg_dns_message dm;
  10. mg_dns_parse(data, size, &dm);
  11. mg_dns_parse(NULL, 0, &dm);
  12. struct mg_http_message hm;
  13. mg_http_parse((const char *) data, size, &hm);
  14. mg_http_parse(NULL, 0, &hm);
  15. struct mg_str body = mg_str_n((const char *) data, size);
  16. char tmp[256];
  17. mg_http_get_var(&body, "key", tmp, sizeof(tmp));
  18. mg_http_get_var(&body, "key", NULL, 0);
  19. mg_url_decode((char *) data, size, tmp, sizeof(tmp), 1);
  20. mg_url_decode((char *) data, size, tmp, 1, 1);
  21. mg_url_decode(NULL, 0, tmp, 1, 1);
  22. struct mg_mqtt_message mm;
  23. mg_mqtt_parse(data, size, 0, &mm);
  24. mg_mqtt_parse(NULL, 0, 0, &mm);
  25. mg_mqtt_parse(data, size, 5, &mm);
  26. mg_mqtt_parse(NULL, 0, 5, &mm);
  27. mg_sntp_parse(data, size);
  28. mg_sntp_parse(NULL, 0);
  29. char buf[size * 4 / 3 + 5]; // At least 4 chars and nul termination
  30. mg_base64_decode((char *) data, (int) size, buf);
  31. mg_base64_decode(NULL, 0, buf);
  32. mg_base64_encode(data, (int) size, buf);
  33. mg_base64_encode(NULL, 0, buf);
  34. mg_globmatch((char *) data, size, (char *) data, size);
  35. struct mg_str k, v, s = mg_str_n((char *) data, size);
  36. while (mg_commalist(&s, &k, &v)) k.len = v.len = 0;
  37. int n;
  38. mg_json_get(mg_str_n((char *) data, size), "$", &n);
  39. return 0;
  40. }