Skip to content

Commit 96961f1

Browse files
DavidKorczynskiedsiper
authored andcommitted
tests: internal: fuzzers: add cmetrics decoder fuzzer
Signed-off-by: David Korczynski <[email protected]>
1 parent 0042486 commit 96961f1

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

tests/internal/fuzzers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(UNIT_TESTS_FILES
33
aws_credentials_fuzzer.c
44
base64_fuzzer.c
55
engine_fuzzer.c
6+
cmetrics_decode_fuzz.c
67
config_fuzzer.c
78
config_random_fuzzer.c
89
ctrace_fuzzer.c
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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_opentelemetry.h>
21+
22+
23+
int
24+
LLVMFuzzerTestOneInput(const uint8_t * data, size_t size)
25+
{
26+
struct cfl_list decoded_contexts;
27+
struct cmt *cmt = NULL;
28+
size_t off = 0;
29+
int result;
30+
31+
/* At least one byte is needed for deciding which decoder to use */
32+
if (size < 1) {
33+
return 0;
34+
}
35+
36+
uint8_t decider = data[0] % 2;
37+
38+
/* Adjust data pointer since the first byte is used */
39+
data += 1;
40+
size -= 1;
41+
42+
/* Fuzz a given decoder */
43+
if (decider == 0) {
44+
result = cmt_decode_opentelemetry_create(&decoded_contexts, data, size,
45+
&off);
46+
if (result == CMT_DECODE_OPENTELEMETRY_SUCCESS) {
47+
cmt_decode_opentelemetry_destroy (&decoded_contexts);
48+
}
49+
}
50+
else if (decider == 1) {
51+
result = cmt_decode_msgpack_create(&cmt, (char *) data, size, &off);
52+
if (result == 0) {
53+
cmt_destroy(cmt);
54+
}
55+
}
56+
return 0;
57+
}

0 commit comments

Comments
 (0)