Debian Codegraph @

Xpjproject/tests/fuzz/fuzz-rtcp.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
24 #include <pjmedia/event.h>
25 #include <pjmedia/rtcp.h>
26 #include <pjmedia/rtcp_fb.h>
27
28 #define kMinInputLength 10
29 #define kMaxInputLength 5120
30
31 void rtcp_fb_parser(const void *data, size_t size)
32 {
33 if (size < sizeof(pjmedia_rtcp_fb_common)) {
34 return;
35 }
36
37 /* Test NACK parsing */
38 {
39 unsigned nack_cnt = 16;
40 pjmedia_rtcp_fb_nack nack[16];
41 pjmedia_rtcp_fb_parse_nack(data, size, &nack_cnt, nack);
42 }
43
44 /* Test PLI parsing */
45 pjmedia_rtcp_fb_parse_pli(data, size);
46
47 /* Test SLI parsing */
48 {
49 unsigned sli_cnt = 16;
50 pjmedia_rtcp_fb_sli sli[16];
51 pjmedia_rtcp_fb_parse_sli(data, size, &sli_cnt, sli);
52 }
53
54 /* Test RPSI parsing */
55 {
56 pjmedia_rtcp_fb_rpsi rpsi;
57 pjmedia_rtcp_fb_parse_rpsi(data, size, &rpsi);
58 }
59 }
60
61 int rtcp_parser(char *data, size_t size)
62 {
63
64 int ret = 0;
65 pjmedia_rtcp_session_setting setting;
66 pjmedia_rtcp_session session;
67
68 pjmedia_rtcp_session_setting_default(&setting);
69 setting.clock_rate = 8000;
70 setting.samples_per_frame = 160;
71 pjmedia_rtcp_init2(&session, &setting);
72
73 /* Test integrated RTCP parsing */
74 pjmedia_rtcp_rx_rtcp(&session, data, size);
75
76 /* Test RTCP-FB message types (NACK, PLI, SLI, RPSI) */
77 rtcp_fb_parser(data, size);
78
79 return ret;
80 }
81
82 extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
83 {
84 char *data;
85 int ret = 0;
86 pj_caching_pool caching_pool;
87 pj_pool_t *pool;
88
89 if (Size < kMinInputLength || Size > kMaxInputLength) {
90 return 1;
91 }
92
93 /* Add null termination for the data */
94 data = (char *)calloc((Size+1), sizeof(char));
95 memcpy((void *)data, (void *)Data, Size);
96
97 /* Init */
98 pj_init();
99 pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
100 pool = pj_pool_create(&caching_pool.factory, "test", 1000, 1000, NULL);
101 pj_log_set_level(0);
102
103 pjmedia_event_mgr_create(pool, 0, NULL);
104
105 /* Fuzz */
106 ret = rtcp_parser(data, Size);
107
108 free(data);
109 pjmedia_event_mgr_destroy(pjmedia_event_mgr_instance());
110 pj_pool_release(pool);
111 pj_caching_pool_destroy(&caching_pool);
112
113 return ret;
114 }