Skip to content

Commit

Permalink
tests: internal: fuzzers: add timeout checks and add license. (fluent…
Browse files Browse the repository at this point in the history
…#3560)

Signed-off-by: davkor <[email protected]>
  • Loading branch information
DavidKorczynski authored and Shikugawa committed Jun 14, 2021
1 parent 3ac5b0e commit 8f286db
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
20 changes: 20 additions & 0 deletions tests/internal/fuzzers/flb_fuzz_header.h
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
#include <string.h>

#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)
{
Expand Down
5 changes: 4 additions & 1 deletion tests/internal/fuzzers/flb_json_fuzzer.c
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -19,9 +19,12 @@
#include <stdint.h>
#include <fluent-bit/flb_pack.h>
#include <fluent-bit/flb_str.h>
#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;
Expand Down
20 changes: 20 additions & 0 deletions tests/internal/fuzzers/parse_json_fuzzer.c
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <fluent-bit/flb_time.h>
#include <fluent-bit/flb_parser.h>
#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;
Expand Down
19 changes: 19 additions & 0 deletions tests/internal/fuzzers/parser_fuzzer.c
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
#include <string.h>
#include <stdlib.h>
Expand All @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion tests/internal/fuzzers/utils_fuzzer.c
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
#include <string.h>
#include <stdlib.h>
Expand All @@ -9,10 +27,12 @@
#include <fluent-bit/flb_uri.h>
#include <fluent-bit/flb_sha512.h>
#include <fluent-bit/flb_regex.h>
#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;
}
Expand Down

0 comments on commit 8f286db

Please sign in to comment.