Debian Codegraph @

Xpjproject/tests/fuzz/fuzz-uri.c

raw symbols SCIP
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
22 #include <pjlib.h>
23 #include <pjlib-util.h>
24 //#include <sip_uri.h>
25
26 #include <pjlib.h>
27 #include <pjlib-util.h>
28 #include <pjsip.h>
29 #include <pjsip/sip_types.h>
30
31 #include <pjsip.h>
32 #include <pjlib.h>
33
34
35 #define kMinInputLength 10
36 #define kMaxInputLength 1024
37
38 /* Defined in sip_parser.c */
39 void init_sip_parser(void);
40 void deinit_sip_parser(void);
41
42 pj_pool_factory *mem;
43
44 int uri_parse(uint8_t *data, size_t Size) {
45
46 pj_status_t status = 0 ;
47 pj_pool_t *pool;
48 pjsip_uri *uri;
49
50 pool = pj_pool_create(mem, "uri", 1000, 1000, NULL);
51
52 uri = pjsip_parse_uri(pool, (char *)data, Size, 0);
53
54 if (!uri) {
55 status = 1;
56 }
57
58 pj_pool_release(pool);
59
60 return status;
61 }
62
63 extern int
64 LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
65 {
66
67 if (Size < kMinInputLength || Size > kMaxInputLength) {
68 return 1;
69 }
70
71 int ret = 0;
72 uint8_t *data;
73 pj_caching_pool caching_pool;
74
75 /* Add NULL byte */
76 data = (uint8_t *)calloc((Size+1), sizeof(uint8_t));
77 memcpy((void *)data, (void *)Data, Size);
78
79 /* init Calls */
80 pj_init();
81 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0);
82 pj_log_set_level(0);
83
84 mem = &caching_pool.factory;
85
86 init_sip_parser();
87
88 /* Call fuzzer */
89 ret = uri_parse(data, Size);
90
91 free(data);
92 deinit_sip_parser();
93 pj_caching_pool_destroy(&caching_pool);
94
95 return ret;
96 }