Coverage Report

Created: 2025-01-28 07:34

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