Skip to content

Commit fcd99ff

Browse files
DavidKorczynskiedsiper
authored andcommitted
tests: internal: fuzzers: split cmetrics decoding
This split is because prometheus has calls to abort https://github.com/fluent/fluent-bit/blob/e8d608b7d7a7c12eae2dfce019f3c263257ed131/lib/cmetrics/src/cmt_decode_prometheus.y#L44 which forces prometheus decoding to cause exits. Consequently, coverage reports are missing for some of the cmetrics decoding files and the aborts also mean fuzzing of the other decoders will be limited. Coverage report: https://storage.googleapis.com/oss-fuzz-coverage/fluent-bit/reports/20250422/linux/src/fluent-bit/lib/cmetrics/src/report.html This the above problems by splitting the decoding harness into two different fuzzers. Signed-off-by: David Korczynski <[email protected]>
1 parent e8d608b commit fcd99ff

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

tests/internal/fuzzers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(UNIT_TESTS_FILES
44
base64_fuzzer.c
55
engine_fuzzer.c
66
cmetrics_decode_fuzz.c
7+
cmetrics_decode_prometheus.c
78
config_fuzzer.c
89
config_random_fuzzer.c
910
ctrace_fuzzer.c

tests/internal/fuzzers/cmetrics_decode_fuzz.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include <cmetrics/cmt_decode_msgpack.h>
2121
#include <cmetrics/cmt_decode_opentelemetry.h>
22-
#include <cmetrics/cmt_decode_prometheus.h>
2322

2423

2524
int
@@ -36,7 +35,7 @@ LLVMFuzzerTestOneInput(const uint8_t * data, size_t size)
3635
return 0;
3736
}
3837

39-
decider = data[0] % 3;
38+
decider = data[0] % 2;
4039

4140
/* Adjust data pointer since the first byte is used */
4241
data += 1;
@@ -50,21 +49,12 @@ LLVMFuzzerTestOneInput(const uint8_t * data, size_t size)
5049
cmt_decode_opentelemetry_destroy (&decoded_contexts);
5150
}
5251
}
53-
else if (decider == 1) {
52+
else {
5453
result = cmt_decode_msgpack_create(&cmt, (char *) data, size, &off);
5554
if (result == 0) {
5655
cmt_destroy(cmt);
5756
}
5857
}
59-
else if (decider == 2) {
60-
if (size == 0) {
61-
return 0;
62-
}
63-
struct cmt_decode_prometheus_parse_opts opts;
64-
result = cmt_decode_prometheus_create(&cmt, data, size, &opts);
65-
if (result == CMT_DECODE_PROMETHEUS_SUCCESS) {
66-
cmt_decode_prometheus_destroy(cmt);
67-
}
68-
}
58+
6959
return 0;
7060
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
20+
#include <cmetrics/cmt_decode_prometheus.h>
21+
22+
23+
int
24+
LLVMFuzzerTestOneInput(const uint8_t * data, size_t size)
25+
{
26+
struct cmt *cmt = NULL;
27+
int result;
28+
29+
/* At least one byte is needed for deciding which decoder to use */
30+
if (size < 1) {
31+
return 0;
32+
}
33+
34+
struct cmt_decode_prometheus_parse_opts opts;
35+
result = cmt_decode_prometheus_create(&cmt, data, size, &opts);
36+
if (result == CMT_DECODE_PROMETHEUS_SUCCESS) {
37+
cmt_decode_prometheus_destroy(cmt);
38+
}
39+
40+
return 0;
41+
}

0 commit comments

Comments
 (0)