/src/pjsip/tests/fuzz/fuzz-url.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 | | |
25 | 29.7k | #define kMinInputLength 10 |
26 | 14.7k | #define kMaxInputLength 1024 |
27 | | |
28 | | pj_pool_factory *mem; |
29 | | |
30 | 218 | int url_parse(uint8_t *data, size_t Size) { |
31 | | |
32 | 218 | pj_str_t surl; |
33 | 218 | pj_http_url hurl; |
34 | | |
35 | 218 | surl.ptr = (char *)data; |
36 | 218 | surl.slen = Size; |
37 | | |
38 | 218 | return pj_http_req_parse_url(&surl, &hurl); |
39 | 218 | } |
40 | | |
41 | | extern int |
42 | | LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
43 | 14.8k | { |
44 | | |
45 | 14.8k | if (Size < kMinInputLength || Size > kMaxInputLength) { |
46 | 340 | return 1; |
47 | 340 | } |
48 | | |
49 | 14.5k | int ret = 0; |
50 | 14.5k | uint8_t *data; |
51 | 14.5k | pj_caching_pool caching_pool; |
52 | | |
53 | | /* Add NULL byte */ |
54 | 14.5k | data = (uint8_t *)calloc((Size+1), sizeof(uint8_t)); |
55 | 14.5k | memcpy((void *)data, (void *)Data, Size); |
56 | | |
57 | | /* init Calls */ |
58 | 14.5k | pj_init(); |
59 | 14.5k | pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0); |
60 | 14.5k | pj_log_set_level(0); |
61 | | |
62 | 14.5k | mem = &caching_pool.factory; |
63 | | |
64 | | /* Call fuzzer */ |
65 | 14.5k | ret = url_parse(data, Size); |
66 | | |
67 | 14.5k | free(data); |
68 | 14.5k | pj_caching_pool_destroy(&caching_pool); |
69 | | |
70 | 14.5k | return ret; |
71 | 14.8k | } |