fuzz-sip.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <pjlib.h>
  23. #include <pjlib-util.h>
  24. #include <pjsip.h>
  25. #include <pjsip/sip_types.h>
  26. #include <pjsip.h>
  27. #include <pjlib.h>
  28. pjsip_endpoint *endpt;
  29. pj_caching_pool caching_pool;
  30. #define POOL_SIZE 8000
  31. #define PJSIP_TEST_MEM_SIZE (2*1024*1024)
  32. #define kMinInputLength 10
  33. #define kMaxInputLength 5120
  34. int sipParser(char *DataFx,size_t Size){
  35. int ret = 0;
  36. pj_pool_t *pool;
  37. pjsip_msg *parsed_msg = NULL;
  38. pjsip_parser_err_report err_list;
  39. pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE);
  40. pj_list_init(&err_list);
  41. parsed_msg = pjsip_parse_msg(pool, DataFx, Size, &err_list);
  42. if (parsed_msg == NULL)
  43. ret = 1;
  44. pjsip_endpt_release_pool(endpt, pool);
  45. return ret;
  46. }
  47. extern int
  48. LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
  49. {/*/home/Ez/project/pjproject/pjsip/src/test/msg_test.c*/
  50. if (Size < kMinInputLength || Size > kMaxInputLength){
  51. return 1;
  52. }
  53. /*Add Extra byte */
  54. char *DataFx;
  55. DataFx = (char *)calloc((Size+1),sizeof(char));
  56. memcpy((void *)DataFx,(void *)Data,Size);
  57. /*init*/
  58. pj_status_t rc;
  59. //pj_status_t status;
  60. pj_log_set_level(0);
  61. rc=pj_init();
  62. rc=pjlib_util_init();
  63. pj_dump_config();
  64. pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy,
  65. PJSIP_TEST_MEM_SIZE );
  66. rc = pjsip_endpt_create(&caching_pool.factory, "endpt", &endpt);
  67. /* Start transaction layer module. */
  68. rc = pjsip_tsx_layer_init_module(endpt);
  69. rc = pjsip_loop_start(endpt, NULL);
  70. /*Calls*/
  71. rc = sipParser(DataFx,Size);
  72. pjsip_endpt_destroy(endpt);
  73. pj_caching_pool_destroy(&caching_pool);
  74. free(DataFx);
  75. return rc;
  76. }