Coverage Report

Created: 2026-09-28 07:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/tests/internal/fuzzers/flb_mp_fuzzer.c
Line
Count
Source
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 2015-2023 The Fluent Bit Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
#include <stdlib.h>
20
#include <stdint.h>
21
#include <fluent-bit/flb_mem.h>
22
#include <fluent-bit/flb_mp.h>
23
24
#include "flb_fuzz_header.h"
25
26
int LLVMFuzzerTestOneInput(unsigned char *data, size_t size)
27
6.24k
{
28
    /* Set flb_malloc_mod to be fuzzer-data dependent */
29
6.24k
    if (size < 5) {
30
4
        return 0;
31
4
    }
32
6.23k
    flb_malloc_p = 0;
33
6.23k
    flb_malloc_mod = *(int*)data;
34
6.23k
    data += 4;
35
6.23k
    size -= 4;
36
37
    /* Avoid division by zero for modulo operations */
38
6.23k
    if (flb_malloc_mod == 0) {
39
32
        flb_malloc_mod = 1;
40
32
    }
41
42
6.23k
    unsigned char decider = *data;
43
6.23k
    data++;
44
6.23k
    size--;
45
46
6.23k
    int out_records;
47
6.23k
    size_t processed_bytes;
48
6.23k
    if (decider % 2 == 0) {
49
2.41k
      flb_mp_validate_log_chunk(data, size, &out_records, &processed_bytes);
50
2.41k
    }
51
3.82k
    else if (decider % 2 == 1) {
52
3.82k
        flb_mp_validate_metric_chunk(data, size, &out_records, &processed_bytes);
53
3.82k
    }
54
6.23k
    return 0;
55
6.24k
}