Coverage Report

Created: 2026-01-10 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pjsip/tests/fuzz/fuzz-sip.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 <pjlib.h>
24
#include <pjlib-util.h>
25
#include <pjsip.h>
26
#include <pjsip/sip_types.h>
27
28
#include <pjsip.h>
29
#include <pjlib.h>
30
31
32
pjsip_endpoint *endpt;
33
pj_caching_pool caching_pool;
34
35
10.0k
#define POOL_SIZE 8000
36
5.04k
#define PJSIP_TEST_MEM_SIZE     (2*1024*1024)
37
38
10.1k
#define kMinInputLength 10
39
5.06k
#define kMaxInputLength 5120
40
41
5.04k
int sipParser(char *DataFx,size_t Size){
42
43
5.04k
    int ret = 0;
44
5.04k
    pj_pool_t *pool;
45
5.04k
    pjsip_msg *parsed_msg = NULL;
46
5.04k
    pjsip_parser_err_report err_list;
47
48
5.04k
    pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE);
49
50
51
5.04k
    pj_list_init(&err_list);
52
53
5.04k
    parsed_msg = pjsip_parse_msg(pool, DataFx, Size, &err_list);
54
    
55
5.04k
    if (parsed_msg == NULL)
56
2.27k
        ret = 1;
57
58
5.04k
    pjsip_endpt_release_pool(endpt, pool);
59
60
5.04k
    return ret;
61
5.04k
}
62
63
extern int
64
LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
65
5.06k
{/*/home/Ez/project/pjproject/pjsip/src/test/msg_test.c*/
66
67
5.06k
    if (Size < kMinInputLength || Size > kMaxInputLength){
68
22
        return 1;
69
22
    }
70
71
/*Add Extra byte */
72
5.04k
    char *DataFx;
73
5.04k
    DataFx = (char *)calloc((Size+1),sizeof(char));
74
5.04k
    memcpy((void *)DataFx,(void *)Data,Size);
75
76
77
/*init*/
78
5.04k
    pj_status_t rc;
79
    //pj_status_t status;
80
81
5.04k
    pj_log_set_level(0);
82
83
5.04k
    rc=pj_init();
84
5.04k
    rc=pjlib_util_init();
85
86
5.04k
    pj_dump_config();
87
88
5.04k
    pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 
89
5.04k
        PJSIP_TEST_MEM_SIZE );
90
91
5.04k
    rc = pjsip_endpt_create(&caching_pool.factory, "endpt", &endpt);
92
93
    /* Start transaction layer module. */
94
5.04k
    rc = pjsip_tsx_layer_init_module(endpt);
95
96
5.04k
    rc = pjsip_loop_start(endpt, NULL);
97
98
/*Calls*/
99
5.04k
    rc = sipParser(DataFx,Size);
100
101
5.04k
    pjsip_endpt_destroy(endpt);
102
5.04k
    pj_caching_pool_destroy(&caching_pool);
103
104
5.04k
    free(DataFx);
105
106
5.04k
    return rc;
107
5.06k
}