fuzz-url.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2023 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <stdio.h>
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <pjlib.h>
  22. #include <pjlib-util.h>
  23. #define kMinInputLength 10
  24. #define kMaxInputLength 1024
  25. pj_pool_factory *mem;
  26. int url_parse(uint8_t *data, size_t Size) {
  27. pj_str_t surl;
  28. pj_http_url hurl;
  29. surl.ptr = (char *)data;
  30. surl.slen = Size;
  31. return pj_http_req_parse_url(&surl, &hurl);
  32. }
  33. extern int
  34. LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
  35. {
  36. if (Size < kMinInputLength || Size > kMaxInputLength) {
  37. return 1;
  38. }
  39. int ret = 0;
  40. uint8_t *data;
  41. pj_caching_pool caching_pool;
  42. /* Add NULL byte */
  43. data = (uint8_t *)calloc((Size+1), sizeof(uint8_t));
  44. memcpy((void *)data, (void *)Data, Size);
  45. /* init Calls */
  46. pj_init();
  47. pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0);
  48. pj_log_set_level(0);
  49. mem = &caching_pool.factory;
  50. /* Call fuzzer */
  51. ret = url_parse(data, Size);
  52. free(data);
  53. pj_caching_pool_destroy(&caching_pool);
  54. return ret;
  55. }