/src/pjsip/tests/fuzz/fuzz-sip.c
Line | Count | Source |
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 | | |
23 | | #include <pjlib.h> |
24 | | #include <pjlib-util.h> |
25 | | #include <pjsip.h> |
26 | | #include <pjsip/sip_types.h> |
27 | | |
28 | | #include <pjsip.h> |
29 | | #include <pjlib.h> |
30 | | |
31 | | |
32 | | pjsip_endpoint *endpt; |
33 | | pj_caching_pool caching_pool; |
34 | | |
35 | 9.64k | #define POOL_SIZE 8000 |
36 | 14.3k | #define PJSIP_TEST_MEM_SIZE (2*1024*1024) |
37 | | |
38 | 29.3k | #define kMinInputLength 10 |
39 | 14.5k | #define kMaxInputLength 5120 |
40 | | |
41 | 4.82k | int sipParser(char *DataFx,size_t Size){ |
42 | | |
43 | 4.82k | int ret = 0; |
44 | 4.82k | pj_pool_t *pool; |
45 | 4.82k | pjsip_msg *parsed_msg = NULL; |
46 | 4.82k | pjsip_parser_err_report err_list; |
47 | | |
48 | 4.82k | pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE); |
49 | | |
50 | | |
51 | 4.82k | pj_list_init(&err_list); |
52 | | |
53 | 4.82k | parsed_msg = pjsip_parse_msg(pool, DataFx, Size, &err_list); |
54 | | |
55 | 4.82k | if (parsed_msg == NULL) |
56 | 2.44k | ret = 1; |
57 | | |
58 | 4.82k | pjsip_endpt_release_pool(endpt, pool); |
59 | | |
60 | 4.82k | return ret; |
61 | 4.82k | } |
62 | | |
63 | | extern int |
64 | | LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
65 | 14.6k | {/*/home/Ez/project/pjproject/pjsip/src/test/msg_test.c*/ |
66 | | |
67 | 14.6k | if (Size < kMinInputLength || Size > kMaxInputLength){ |
68 | 345 | return 1; |
69 | 345 | } |
70 | | |
71 | | /*Add Extra byte */ |
72 | 14.3k | char *DataFx; |
73 | 14.3k | DataFx = (char *)calloc((Size+1),sizeof(char)); |
74 | 14.3k | memcpy((void *)DataFx,(void *)Data,Size); |
75 | | |
76 | | |
77 | | /*init*/ |
78 | 14.3k | pj_status_t rc; |
79 | | //pj_status_t status; |
80 | | |
81 | 14.3k | pj_log_set_level(0); |
82 | | |
83 | 14.3k | rc=pj_init(); |
84 | 14.3k | rc=pjlib_util_init(); |
85 | | |
86 | 14.3k | pj_dump_config(); |
87 | | |
88 | 14.3k | pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, |
89 | 14.3k | PJSIP_TEST_MEM_SIZE ); |
90 | | |
91 | 14.3k | rc = pjsip_endpt_create(&caching_pool.factory, "endpt", &endpt); |
92 | | |
93 | | /* Start transaction layer module. */ |
94 | 14.3k | rc = pjsip_tsx_layer_init_module(endpt); |
95 | | |
96 | 14.3k | rc = pjsip_loop_start(endpt, NULL); |
97 | | |
98 | | /*Calls*/ |
99 | 14.3k | rc = sipParser(DataFx,Size); |
100 | | |
101 | 14.3k | pjsip_endpt_destroy(endpt); |
102 | 14.3k | pj_caching_pool_destroy(&caching_pool); |
103 | | |
104 | 14.3k | free(DataFx); |
105 | | |
106 | 14.3k | return rc; |
107 | 14.6k | } |