From 9a246b836abc19fde4f258fda749dc01a8ffe1a2 Mon Sep 17 00:00:00 2001 From: davkor Date: Wed, 26 May 2021 19:06:42 +0100 Subject: [PATCH] tests: internal: fuzzers: add timeout checks and add license. Signed-off-by: davkor --- tests/internal/fuzzers/flb_fuzz_header.h | 20 ++++++++++++++++++++ tests/internal/fuzzers/flb_json_fuzzer.c | 5 ++++- tests/internal/fuzzers/parse_json_fuzzer.c | 20 ++++++++++++++++++++ tests/internal/fuzzers/parser_fuzzer.c | 19 +++++++++++++++++++ tests/internal/fuzzers/utils_fuzzer.c | 22 +++++++++++++++++++++- 5 files changed, 84 insertions(+), 2 deletions(-) diff --git a/tests/internal/fuzzers/flb_fuzz_header.h b/tests/internal/fuzzers/flb_fuzz_header.h index a10ed04517d..b5c844e6d65 100644 --- a/tests/internal/fuzzers/flb_fuzz_header.h +++ b/tests/internal/fuzzers/flb_fuzz_header.h @@ -1,9 +1,29 @@ +/* Fluent Bit + * ========== + * Copyright (C) 2019-2021 The Fluent Bit Authors + * Copyright (C) 2015-2018 Treasure Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include #include #define GET_MOD_EQ(max, idx) (data[0] % max) == idx #define MOVE_INPUT(offset) data += offset; size -= offset; +#define TIMEOUT_GUARD if (size > 32768) return 0; + char *get_null_terminated(size_t size, const uint8_t **data, size_t *total_data_size) { diff --git a/tests/internal/fuzzers/flb_json_fuzzer.c b/tests/internal/fuzzers/flb_json_fuzzer.c index 79108d02b5f..3034d3831ba 100644 --- a/tests/internal/fuzzers/flb_json_fuzzer.c +++ b/tests/internal/fuzzers/flb_json_fuzzer.c @@ -1,6 +1,6 @@ /* Fluent Bit * ========== - * Copyright (C) 2019-2020 The Fluent Bit Authors + * Copyright (C) 2019-2021 The Fluent Bit Authors * Copyright (C) 2015-2018 Treasure Data Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,12 @@ #include #include #include +#include "flb_fuzz_header.h" int LLVMFuzzerTestOneInput(unsigned char *data, size_t size) { + TIMEOUT_GUARD + /* json packer */ char *out_buf = NULL; size_t out_size; diff --git a/tests/internal/fuzzers/parse_json_fuzzer.c b/tests/internal/fuzzers/parse_json_fuzzer.c index d12101b5363..431f6feba29 100644 --- a/tests/internal/fuzzers/parse_json_fuzzer.c +++ b/tests/internal/fuzzers/parse_json_fuzzer.c @@ -1,10 +1,30 @@ +/* Fluent Bit + * ========== + * Copyright (C) 2019-2021 The Fluent Bit Authors + * Copyright (C) 2015-2018 Treasure Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include #include #include #include #include +#include "flb_fuzz_header.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size){ + TIMEOUT_GUARD + void *out_buf = NULL; size_t out_size = 0; struct flb_time out_time; diff --git a/tests/internal/fuzzers/parser_fuzzer.c b/tests/internal/fuzzers/parser_fuzzer.c index e0cca1d121c..56f744a5d0e 100644 --- a/tests/internal/fuzzers/parser_fuzzer.c +++ b/tests/internal/fuzzers/parser_fuzzer.c @@ -1,3 +1,20 @@ +/* Fluent Bit + * ========== + * Copyright (C) 2019-2021 The Fluent Bit Authors + * Copyright (C) 2015-2018 Treasure Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include #include #include @@ -12,6 +29,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + TIMEOUT_GUARD + char *format = NULL; char *time_fmt = NULL; char *time_key = NULL; diff --git a/tests/internal/fuzzers/utils_fuzzer.c b/tests/internal/fuzzers/utils_fuzzer.c index 56daf081870..7555390862d 100644 --- a/tests/internal/fuzzers/utils_fuzzer.c +++ b/tests/internal/fuzzers/utils_fuzzer.c @@ -1,3 +1,21 @@ +/* Fluent Bit + * ========== + * Copyright (C) 2019-2021 The Fluent Bit Authors + * Copyright (C) 2015-2018 Treasure Data Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include #include #include @@ -9,10 +27,12 @@ #include #include #include +#include "flb_fuzz_header.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* We need a bit of data in this fuzzer */ + TIMEOUT_GUARD + if (size < 600) { return 0; }