fuzz-rtcp.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <pjmedia/event.h>
  23. #include <pjmedia/rtcp.h>
  24. #define kMinInputLength 10
  25. #define kMaxInputLength 5120
  26. int rtcp_parser(char *data, size_t size)
  27. {
  28. int ret = 0;
  29. pjmedia_rtcp_session_setting setting;
  30. pjmedia_rtcp_session session;
  31. pjmedia_rtcp_session_setting_default(&setting);
  32. setting.clock_rate = 8000;
  33. setting.samples_per_frame = 160;
  34. pjmedia_rtcp_init2(&session, &setting);
  35. pjmedia_rtcp_rx_rtcp(&session, data, size);
  36. return ret;
  37. }
  38. extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
  39. {
  40. char *data;
  41. int ret = 0;
  42. pj_caching_pool caching_pool;
  43. pj_pool_t *pool;
  44. if (Size < kMinInputLength || Size > kMaxInputLength) {
  45. return 1;
  46. }
  47. /* Add null termination for the data */
  48. data = (char *)calloc((Size+1), sizeof(char));
  49. memcpy((void *)data, (void *)Data, Size);
  50. /* Init */
  51. pj_init();
  52. pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
  53. pool = pj_pool_create(&caching_pool.factory, "test", 1000, 1000, NULL);
  54. pj_log_set_level(0);
  55. pjmedia_event_mgr_create(pool, 0, NULL);
  56. /* Fuzz */
  57. ret = rtcp_parser(data, Size);
  58. free(data);
  59. pjmedia_event_mgr_destroy(pjmedia_event_mgr_instance());
  60. pj_pool_release(pool);
  61. pj_caching_pool_destroy(&caching_pool);
  62. return ret;
  63. }