Coverage Report

Created: 2025-11-01 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/unit/fuzzing/nxt_json_fuzz.c
Line
Count
Source
1
/*
2
 * Copyright (C) NGINX, Inc.
3
 */
4
5
#include <nxt_main.h>
6
#include <nxt_conf.h>
7
#include <nxt_router.h>
8
9
12.6k
#define KMININPUTLENGTH 2
10
6.32k
#define KMAXINPUTLENGTH 1024
11
12
13
extern int LLVMFuzzerInitialize(int *argc, char ***argv);
14
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
15
16
17
extern char  **environ;
18
19
20
int
21
LLVMFuzzerInitialize(int *argc, char ***argv)
22
2
{
23
2
    if (nxt_lib_start("fuzzing", NULL, &environ) != NXT_OK) {
24
0
        return NXT_ERROR;
25
0
    }
26
27
2
    return 0;
28
2
}
29
30
31
int
32
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
33
6.32k
{
34
6.32k
    nxt_mp_t                *mp;
35
6.32k
    nxt_str_t               input;
36
6.32k
    nxt_thread_t            *thr;
37
6.32k
    nxt_runtime_t           *rt;
38
6.32k
    nxt_conf_value_t        *conf;
39
6.32k
    nxt_conf_validation_t   vldt;
40
6.32k
    nxt_conf_json_pretty_t  pretty;
41
42
6.32k
    if (size < KMININPUTLENGTH || size > KMAXINPUTLENGTH) {
43
22
        return 0;
44
22
    }
45
46
6.30k
    thr = nxt_thread();
47
48
6.30k
    mp = nxt_mp_create(1024, 128, 256, 32);
49
6.30k
    if (mp == NULL) {
50
0
        return 0;
51
0
    }
52
53
6.30k
    rt = nxt_mp_zget(mp, sizeof(nxt_runtime_t));
54
6.30k
    if (rt == NULL) {
55
0
        goto failed;
56
0
    }
57
58
6.30k
    rt->languages = nxt_array_create(mp, 1, sizeof(nxt_app_lang_module_t));
59
6.30k
    if (rt->languages == NULL) {
60
0
        goto failed;
61
0
    }
62
63
6.30k
    input.start = (u_char *)data;
64
6.30k
    input.length = size;
65
66
6.30k
    thr->runtime = rt;
67
6.30k
    rt->mem_pool = mp;
68
69
6.30k
    nxt_memzero(&pretty, sizeof(nxt_conf_json_pretty_t));
70
6.30k
    nxt_memzero(&vldt, sizeof(nxt_conf_validation_t));
71
72
6.30k
    conf = nxt_conf_json_parse_str(mp, &input);
73
6.30k
    if (conf == NULL) {
74
1.96k
        goto failed;
75
1.96k
    }
76
77
4.34k
    nxt_conf_json_length(conf, NULL);
78
4.34k
    nxt_conf_json_length(conf, &pretty);
79
80
4.34k
    vldt.pool = nxt_mp_create(1024, 128, 256, 32);
81
4.34k
    if (vldt.pool == NULL) {
82
0
        goto failed;
83
0
    }
84
85
4.34k
    vldt.conf = conf;
86
4.34k
    vldt.conf_pool = mp;
87
4.34k
    vldt.ver = NXT_VERNUM;
88
89
4.34k
    nxt_conf_validate(&vldt);
90
4.34k
    nxt_mp_destroy(vldt.pool);
91
92
6.30k
failed:
93
94
6.30k
    nxt_mp_destroy(mp);
95
96
6.30k
    return 0;
97
4.34k
}