fuzz-sdp.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <stdio.h>
  20. #include <stdint.h>
  21. #include <stdlib.h>
  22. #include <pjmedia.h>
  23. #include <pjlib.h>
  24. #include <pjmedia/sdp.h>
  25. #include <pjmedia/sdp_neg.h>
  26. #define kMinInputLength 10
  27. #define kMaxInputLength 5120
  28. pj_pool_factory *mem;
  29. int sdp_parser(char *DataFx,size_t Size){
  30. int ret = 0;
  31. pj_pool_t *pool;
  32. pjmedia_sdp_session *sdp;
  33. pj_status_t status;
  34. pool = pj_pool_create(mem, "sdp_neg_test", 4000, 4000, NULL);
  35. status = pjmedia_sdp_parse(pool, DataFx, Size,&sdp);
  36. if (status != PJ_SUCCESS){
  37. ret = 1;
  38. goto end;
  39. }
  40. status = pjmedia_sdp_validate(sdp);
  41. end:
  42. pj_pool_release(pool);
  43. return ret;
  44. }
  45. extern int
  46. LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
  47. {/*pjproject/pjmedia/src/test/sdp_neg_test.c*/
  48. if (Size < kMinInputLength || Size > kMaxInputLength){
  49. return 1;
  50. }
  51. /*Add Extra byte */
  52. char *DataFx;
  53. DataFx = (char *)calloc((Size+1),sizeof(char));
  54. memcpy((void *)DataFx,(void *)Data,Size);
  55. /*init*/
  56. int ret = 0;
  57. pj_caching_pool caching_pool;
  58. pj_pool_t *pool;
  59. pj_init();
  60. pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
  61. pool = pj_pool_create(&caching_pool.factory, "test", 1000, 512, NULL);
  62. pj_log_set_level(0);
  63. mem = &caching_pool.factory;
  64. pjmedia_event_mgr_create(pool, 0, NULL);
  65. /*Call*/
  66. ret = sdp_parser(DataFx,Size);
  67. /*Free*/
  68. pjmedia_event_mgr_destroy(pjmedia_event_mgr_instance());
  69. pj_pool_release(pool);
  70. pj_caching_pool_destroy(&caching_pool);
  71. free(DataFx);
  72. return ret;
  73. }