Coverage Report

Created: 2025-06-24 08:09

/src/fluent-bit/tests/internal/fuzzers/config_random_fuzzer.c
Line
Count
Source (jump to first uncovered line)
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
676
{
27
    /* Set fuzzer-malloc chance of failure */
28
676
    flb_malloc_p = 0;
29
676
    flb_malloc_mod = 25000;
30
31
    /* Limit the size of the config files to 32KB. */
32
676
    if (size > 32768) {
33
1
        return 0;
34
1
    }
35
36
    /* Write the config file to a location we know OSS-Fuzz has */
37
675
    char filename[256];
38
675
    sprintf(filename, "/tmp/libfuzzer.%d", getpid());
39
675
    FILE *fp = fopen(filename, "wb");
40
675
    if (!fp) {
41
0
        return 0;
42
0
    }
43
675
    fwrite(data, size, 1, fp);
44
675
    fclose(fp);
45
46
    /* Now parse a random config file */
47
675
    struct flb_config *config = NULL;
48
675
    config = flb_config_init();
49
675
    flb_parser_conf_file(filename, config);
50
675
    flb_parser_exit(config);
51
675
    flb_config_exit(config);
52
53
    /* Cleanup written config file */
54
675
    unlink(filename);
55
56
675
    return 0;
57
675
}