Coverage Report

Created: 2026-01-21 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/tests/internal/fuzzers/config_random_fuzzer.c
Line
Count
Source
1
/*  Fluent Bit
2
 *  ==========
3
 *  Copyright (C) 2019-2021 The Fluent Bit Authors
4
 *  Copyright (C) 2015-2018 Treasure Data Inc.
5
 *
6
 *  Licensed under the Apache License, Version 2.0 (the "License");
7
 *  you may not use this file except in compliance with the License.
8
 *  You may obtain a copy of the License at
9
 *
10
 *      http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *  Unless required by applicable law or agreed to in writing, software
13
 *  distributed under the License is distributed on an "AS IS" BASIS,
14
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *  See the License for the specific language governing permissions and
16
 *  limitations under the License.
17
 */
18
#include <stdint.h>
19
#include <string.h>
20
#include <stdlib.h>
21
#include <fluent-bit/flb_parser.h>
22
#include <fluent-bit/flb_slist.h>
23
#include "flb_fuzz_header.h"
24
25
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
26
828
{
27
    /* Set fuzzer-malloc chance of failure */
28
828
    flb_malloc_p = 0;
29
828
    flb_malloc_mod = 25000;
30
31
    /* Limit the size of the config files to 32KB. */
32
828
    if (size > 32768) {
33
6
        return 0;
34
6
    }
35
36
    /* Write the config file to a location we know OSS-Fuzz has */
37
822
    char filename[256];
38
822
    sprintf(filename, "/tmp/libfuzzer.%d", getpid());
39
822
    FILE *fp = fopen(filename, "wb");
40
822
    if (!fp) {
41
0
        return 0;
42
0
    }
43
822
    fwrite(data, size, 1, fp);
44
822
    fclose(fp);
45
46
    /* Now parse a random config file */
47
822
    struct flb_config *config = NULL;
48
822
    config = flb_config_init();
49
822
    flb_parser_conf_file(filename, config);
50
822
    flb_parser_exit(config);
51
822
    flb_config_exit(config);
52
53
    /* Cleanup written config file */
54
822
    unlink(filename);
55
56
822
    return 0;
57
822
}