/src/fluent-bit/tests/internal/fuzzers/flb_mp_fuzzer.c
Line | Count | Source (jump to first uncovered line) |
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 | 136 | { |
28 | | /* Set flb_malloc_mod to be fuzzer-data dependent */ |
29 | 136 | if (size < 5) { |
30 | 0 | return 0; |
31 | 0 | } |
32 | 136 | flb_malloc_p = 0; |
33 | 136 | flb_malloc_mod = *(int*)data; |
34 | 136 | data += 4; |
35 | 136 | size -= 4; |
36 | | |
37 | | /* Avoid division by zero for modulo operations */ |
38 | 136 | if (flb_malloc_mod == 0) { |
39 | 2 | flb_malloc_mod = 1; |
40 | 2 | } |
41 | | |
42 | 136 | unsigned char decider = *data; |
43 | 136 | data++; |
44 | 136 | size--; |
45 | | |
46 | 136 | int out_records; |
47 | 136 | size_t processed_bytes; |
48 | 136 | if (decider % 2 == 0) { |
49 | 23 | flb_mp_validate_log_chunk(data, size, &out_records, &processed_bytes); |
50 | 23 | } |
51 | 113 | else if (decider % 2 == 1) { |
52 | 113 | flb_mp_validate_metric_chunk(data, size, &out_records, &processed_bytes); |
53 | 113 | } |
54 | 136 | return 0; |
55 | 136 | } |