/src/pjsip/tests/fuzz/fuzz-uri.c
Line | Count | Source |
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 | 29.4k | #define kMinInputLength 10 |
36 | 14.6k | #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 | 1.40k | int uri_parse(uint8_t *data, size_t Size) { |
45 | | |
46 | 1.40k | pj_status_t status = 0 ; |
47 | 1.40k | pj_pool_t *pool; |
48 | 1.40k | pjsip_uri *uri; |
49 | | |
50 | 1.40k | pool = pj_pool_create(mem, "uri", 1000, 1000, NULL); |
51 | | |
52 | 1.40k | uri = pjsip_parse_uri(pool, (char *)data, Size, 0); |
53 | | |
54 | 1.40k | if (!uri) { |
55 | 726 | status = 1; |
56 | 726 | } |
57 | | |
58 | 1.40k | pj_pool_release(pool); |
59 | | |
60 | 1.40k | return status; |
61 | 1.40k | } |
62 | | |
63 | | extern int |
64 | | LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
65 | 14.7k | { |
66 | | |
67 | 14.7k | if (Size < kMinInputLength || Size > kMaxInputLength) { |
68 | 344 | return 1; |
69 | 344 | } |
70 | | |
71 | 14.3k | int ret = 0; |
72 | 14.3k | uint8_t *data; |
73 | 14.3k | pj_caching_pool caching_pool; |
74 | | |
75 | | /* Add NULL byte */ |
76 | 14.3k | data = (uint8_t *)calloc((Size+1), sizeof(uint8_t)); |
77 | 14.3k | memcpy((void *)data, (void *)Data, Size); |
78 | | |
79 | | /* init Calls */ |
80 | 14.3k | pj_init(); |
81 | 14.3k | pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0); |
82 | 14.3k | pj_log_set_level(0); |
83 | | |
84 | 14.3k | mem = &caching_pool.factory; |
85 | | |
86 | 14.3k | init_sip_parser(); |
87 | | |
88 | | /* Call fuzzer */ |
89 | 14.3k | ret = uri_parse(data, Size); |
90 | | |
91 | 14.3k | free(data); |
92 | 14.3k | deinit_sip_parser(); |
93 | 14.3k | pj_caching_pool_destroy(&caching_pool); |
94 | | |
95 | 14.3k | return ret; |
96 | 14.7k | } |