/src/pjsip/tests/fuzz/fuzz-http.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 "../../pjlib-util/src/pjlib-util/http_client.c" |
25 | | |
26 | 29.4k | #define kMinInputLength 10 |
27 | 14.6k | #define kMaxInputLength 1024 |
28 | | |
29 | | pj_pool_factory *mem; |
30 | | |
31 | 576 | int http_parse(uint8_t *data, size_t Size) { |
32 | | |
33 | 576 | int ret; |
34 | 576 | pj_pool_t *pool; |
35 | 576 | pj_size_t rem; |
36 | 576 | pj_http_resp response; |
37 | | |
38 | 576 | pool = pj_pool_create(mem, "http", 1000, 1000, NULL); |
39 | | |
40 | 576 | ret = http_response_parse(pool, &response, data, Size, &rem); |
41 | | |
42 | 576 | pj_pool_release(pool); |
43 | | |
44 | 576 | return ret; |
45 | 576 | } |
46 | | |
47 | | extern int |
48 | | LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
49 | 14.7k | { |
50 | | |
51 | 14.7k | if (Size < kMinInputLength || Size > kMaxInputLength) { |
52 | 344 | return 1; |
53 | 344 | } |
54 | | |
55 | 14.3k | int ret = 0; |
56 | 14.3k | uint8_t *data; |
57 | 14.3k | pj_caching_pool caching_pool; |
58 | | |
59 | | /* Add NULL byte */ |
60 | 14.3k | data = (uint8_t *)calloc((Size+1), sizeof(uint8_t)); |
61 | 14.3k | memcpy((void *)data, (void *)Data, Size); |
62 | | |
63 | | /* init Calls */ |
64 | 14.3k | pj_init(); |
65 | 14.3k | pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0); |
66 | 14.3k | pj_log_set_level(0); |
67 | | |
68 | 14.3k | mem = &caching_pool.factory; |
69 | | |
70 | | /* Call fuzzer */ |
71 | 14.3k | ret = http_parse(data, Size); |
72 | | |
73 | 14.3k | free(data); |
74 | 14.3k | pj_caching_pool_destroy(&caching_pool); |
75 | | |
76 | 14.3k | return ret; |
77 | 14.7k | } |