/src/pjsip/tests/fuzz/fuzz-sdp.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 <pjmedia.h> |
24 | | #include <pjlib.h> |
25 | | |
26 | | #include <pjmedia/sdp.h> |
27 | | #include <pjmedia/sdp_neg.h> |
28 | | |
29 | 27.9k | #define kMinInputLength 10 |
30 | 13.9k | #define kMaxInputLength 5120 |
31 | | |
32 | | pj_pool_factory *mem; |
33 | | |
34 | 2.14k | int sdp_parser(char *DataFx,size_t Size){ |
35 | | |
36 | 2.14k | int ret = 0; |
37 | 2.14k | pj_pool_t *pool; |
38 | 2.14k | pjmedia_sdp_session *sdp; |
39 | 2.14k | pj_status_t status; |
40 | | |
41 | 2.14k | pool = pj_pool_create(mem, "sdp_neg_test", 4000, 4000, NULL); |
42 | | |
43 | 2.14k | status = pjmedia_sdp_parse(pool, DataFx, Size,&sdp); |
44 | | |
45 | 2.14k | if (status != PJ_SUCCESS){ |
46 | 474 | ret = 1; |
47 | 474 | goto end; |
48 | 474 | } |
49 | | |
50 | 1.66k | status = pjmedia_sdp_validate(sdp); |
51 | | |
52 | 2.14k | end: |
53 | 2.14k | pj_pool_release(pool); |
54 | | |
55 | 2.14k | return ret; |
56 | 1.66k | } |
57 | | |
58 | | extern int |
59 | | LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
60 | 13.9k | {/*pjproject/pjmedia/src/test/sdp_neg_test.c*/ |
61 | | |
62 | 13.9k | if (Size < kMinInputLength || Size > kMaxInputLength){ |
63 | 328 | return 1; |
64 | 328 | } |
65 | | |
66 | | /*Add Extra byte */ |
67 | 13.6k | char *DataFx; |
68 | 13.6k | DataFx = (char *)calloc((Size+1),sizeof(char)); |
69 | 13.6k | memcpy((void *)DataFx,(void *)Data,Size); |
70 | | |
71 | | /*init*/ |
72 | 13.6k | int ret = 0; |
73 | 13.6k | pj_caching_pool caching_pool; |
74 | 13.6k | pj_pool_t *pool; |
75 | | |
76 | 13.6k | pj_init(); |
77 | 13.6k | pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); |
78 | 13.6k | pool = pj_pool_create(&caching_pool.factory, "test", 1000, 512, NULL); |
79 | | |
80 | 13.6k | pj_log_set_level(0); |
81 | | |
82 | 13.6k | mem = &caching_pool.factory; |
83 | | |
84 | 13.6k | pjmedia_event_mgr_create(pool, 0, NULL); |
85 | | |
86 | | /*Call*/ |
87 | 13.6k | ret = sdp_parser(DataFx,Size); |
88 | | |
89 | | /*Free*/ |
90 | 13.6k | pjmedia_event_mgr_destroy(pjmedia_event_mgr_instance()); |
91 | 13.6k | pj_pool_release(pool); |
92 | 13.6k | pj_caching_pool_destroy(&caching_pool); |
93 | | |
94 | 13.6k | free(DataFx); |
95 | 13.6k | return ret; |
96 | 13.9k | } |