Coverage Report

Created: 2025-08-26 06:58

/src/pjsip/tests/fuzz/fuzz-rtcp.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
24
#include <pjmedia/event.h>
25
#include <pjmedia/rtcp.h>
26
27
29.5k
#define kMinInputLength 10
28
14.6k
#define kMaxInputLength 5120
29
30
int rtcp_parser(char *data, size_t size)
31
657
{
32
33
657
    int ret = 0;
34
657
    pjmedia_rtcp_session_setting setting;
35
657
    pjmedia_rtcp_session session;
36
37
657
    pjmedia_rtcp_session_setting_default(&setting);
38
657
    setting.clock_rate = 8000;
39
657
    setting.samples_per_frame = 160;
40
657
    pjmedia_rtcp_init2(&session, &setting);
41
42
657
    pjmedia_rtcp_rx_rtcp(&session, data, size);
43
44
657
    return ret;
45
657
}
46
47
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
48
14.7k
{
49
14.7k
    char *data;
50
14.7k
    int ret = 0;
51
14.7k
    pj_caching_pool caching_pool;
52
14.7k
    pj_pool_t *pool;
53
54
14.7k
    if (Size < kMinInputLength || Size > kMaxInputLength) {
55
344
        return 1;
56
344
    }
57
58
    /* Add null termination for the data */
59
14.4k
    data = (char *)calloc((Size+1), sizeof(char));
60
14.4k
    memcpy((void *)data, (void *)Data, Size);
61
62
    /* Init */
63
14.4k
    pj_init();
64
14.4k
    pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
65
14.4k
    pool = pj_pool_create(&caching_pool.factory, "test", 1000, 1000, NULL);
66
14.4k
    pj_log_set_level(0);
67
68
14.4k
    pjmedia_event_mgr_create(pool, 0, NULL);
69
70
    /* Fuzz */
71
14.4k
    ret = rtcp_parser(data, Size);
72
73
14.4k
    free(data);
74
14.4k
    pjmedia_event_mgr_destroy(pjmedia_event_mgr_instance());
75
14.4k
    pj_pool_release(pool);
76
14.4k
    pj_caching_pool_destroy(&caching_pool);
77
78
14.4k
    return ret;
79
14.7k
}