Coverage Report

Created: 2025-10-28 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pjsip/tests/fuzz/fuzz-stun.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
25
#include <pjnath.h>
26
27
1.94k
#define kMinInputLength 10
28
964
#define kMaxInputLength 5120
29
30
pj_pool_factory *mem;
31
32
945
int stun_parse(uint8_t *data,size_t Size) {
33
34
945
    pj_status_t status;
35
945
    pj_pool_t *pool;
36
945
    pj_stun_msg *msg;
37
945
    pj_stun_auth_cred cred;
38
39
945
    const pj_str_t USERNAME = {"A", 1};
40
945
    const pj_str_t PASSWORD = {"A", 1};
41
42
945
    pool = pj_pool_create(mem, "decode_test", 1024, 1024, NULL);
43
44
945
    status = pj_stun_msg_decode(pool, data, Size, PJ_STUN_IS_DATAGRAM | PJ_STUN_CHECK_PACKET, &msg, NULL, NULL);
45
945
    if(status != PJ_SUCCESS){
46
360
        goto ret_error;
47
360
    }
48
49
585
    pj_bzero(&cred, sizeof(cred));
50
585
    cred.type = PJ_STUN_AUTH_CRED_STATIC;
51
585
    cred.data.static_cred.username = USERNAME;
52
585
    cred.data.static_cred.data_type = PJ_STUN_PASSWD_PLAIN;
53
585
    cred.data.static_cred.data = PASSWORD;
54
55
585
    pj_stun_authenticate_request(data, (unsigned)Size, msg, &cred, pool, NULL, NULL);
56
57
585
    pj_pool_release(pool);
58
585
    return status;
59
60
360
ret_error:
61
360
    pj_pool_release(pool);
62
360
    return status;
63
945
}
64
65
66
extern int
67
LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
68
970
{
69
70
970
    if (Size < kMinInputLength || Size > kMaxInputLength) {
71
25
        return 1;
72
25
    }
73
74
945
    int ret = 0;
75
945
    uint8_t *data;
76
945
    pj_caching_pool caching_pool;
77
78
    /* Add NULL byte */
79
945
    data = (uint8_t *)calloc((Size+1), sizeof(uint8_t));
80
945
    memcpy((void *)data, (void *)Data, Size);
81
82
    /* init Calls */
83
945
    pj_init();
84
945
    pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0);
85
945
    pj_log_set_level(0);
86
87
945
    mem = &caching_pool.factory;
88
89
    /* Call fuzzer */
90
945
    ret = stun_parse(data, Size);
91
92
945
    free(data);
93
945
    pj_caching_pool_destroy(&caching_pool);
94
95
945
    return ret;
96
970
}