ares-test-fuzz.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <stddef.h>
  2. #include "ares.h"
  3. // Entrypoint for Clang's libfuzzer
  4. int LLVMFuzzerTestOneInput(const unsigned char *data,
  5. unsigned long size) {
  6. // Feed the data into each of the ares_parse_*_reply functions.
  7. struct hostent *host = NULL;
  8. struct ares_addrttl info[5];
  9. int count = 5;
  10. ares_parse_a_reply(data, size, &host, info, &count);
  11. if (host) ares_free_hostent(host);
  12. host = NULL;
  13. struct ares_addr6ttl info6[5];
  14. count = 5;
  15. ares_parse_aaaa_reply(data, size, &host, info6, &count);
  16. if (host) ares_free_hostent(host);
  17. host = NULL;
  18. unsigned char addrv4[4] = {0x10, 0x20, 0x30, 0x40};
  19. ares_parse_ptr_reply(data, size, addrv4, sizeof(addrv4), AF_INET, &host);
  20. if (host) ares_free_hostent(host);
  21. host = NULL;
  22. ares_parse_ns_reply(data, size, &host);
  23. if (host) ares_free_hostent(host);
  24. struct ares_srv_reply* srv = NULL;
  25. ares_parse_srv_reply(data, size, &srv);
  26. if (srv) ares_free_data(srv);
  27. struct ares_mx_reply* mx = NULL;
  28. ares_parse_mx_reply(data, size, &mx);
  29. if (mx) ares_free_data(mx);
  30. struct ares_txt_reply* txt = NULL;
  31. ares_parse_txt_reply(data, size, &txt);
  32. if (txt) ares_free_data(txt);
  33. struct ares_soa_reply* soa = NULL;
  34. ares_parse_soa_reply(data, size, &soa);
  35. if (soa) ares_free_data(soa);
  36. struct ares_naptr_reply* naptr = NULL;
  37. ares_parse_naptr_reply(data, size, &naptr);
  38. if (naptr) ares_free_data(naptr);
  39. struct ares_caa_reply* caa = NULL;
  40. ares_parse_caa_reply(data, size, &caa);
  41. if (caa) ares_free_data(caa);
  42. struct ares_uri_reply* uri = NULL;
  43. ares_parse_uri_reply(data, size, &uri);
  44. if (uri) ares_free_data(uri);
  45. return 0;
  46. }