Coverage Report

Created: 2025-07-04 07:08

/src/fluent-bit/tests/internal/fuzzers/aws_util_fuzzer.c
Line
Count
Source
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 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 <stdint.h>
21
#include <fluent-bit.h>
22
#include <fluent-bit/flb_sds.h>
23
#include <fluent-bit/flb_aws_util.h>
24
#include <fluent-bit/flb_mem.h>
25
#include "flb_fuzz_header.h"
26
27
int initialization_crutch()
28
1.15k
{
29
1.15k
    struct flb_config *config;
30
1.15k
    config = flb_config_init();
31
1.15k
    if (config == NULL) {
32
295
        return -1;
33
295
    }
34
862
    flb_config_exit(config);
35
862
    return 0;
36
1.15k
}
37
38
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
39
643
{
40
643
    char *format = NULL;
41
643
    char *tag = NULL;
42
643
    char *tag_delimiter = NULL;
43
44
    /* Set flb_malloc_mod to be fuzzer-data dependent */
45
643
    if (size < 4) {
46
2
        return 0;
47
2
    }
48
641
    flb_malloc_p = 0;
49
641
    flb_malloc_mod = *(int*)data;
50
641
    data += 4;
51
641
    size -= 4;
52
53
    /* Avoid division by zero for modulo operations */
54
641
    if (flb_malloc_mod == 0) {
55
2
        flb_malloc_mod = 1;
56
2
    }
57
58
641
    if (size < 300) {
59
77
        return 0;
60
77
    }
61
62
564
    format = get_null_terminated(50, &data, &size);
63
564
    tag = get_null_terminated(100, &data, &size);
64
564
    tag_delimiter = get_null_terminated(100, &data, &size);
65
66
564
    struct tm day = { 0, 0, 0, 15, 7, 120};
67
564
    time_t t;
68
564
    memset(&t, 0, sizeof(time_t));
69
70
564
    if (format && tag && tag_delimiter) {
71
564
        if (!initialization_crutch()) {
72
413
            flb_sds_t s3_key_format = NULL;
73
413
            s3_key_format = flb_get_s3_key(format, t, tag, tag_delimiter, 0);
74
413
            if (s3_key_format) {
75
367
                flb_sds_destroy(s3_key_format);
76
367
            }
77
413
            if (size > 200) {
78
310
                char *json_val = get_null_terminated(100, &data, &size);
79
310
                if (json_val != NULL) {
80
310
                    flb_sds_t s1 = flb_aws_error(json_val, strlen(json_val));
81
310
                    if (s1 != NULL) {
82
2
                        flb_sds_destroy(s1);
83
2
                    }
84
310
                    flb_free(json_val);
85
310
                }
86
310
                char *xml_val = get_null_terminated(100, &data, &size);
87
310
                if (xml_val != NULL) {
88
310
                    flb_sds_t s2 = flb_aws_xml_error(xml_val, strlen(xml_val));
89
310
                    if (s2 != NULL) {
90
1
                        flb_sds_destroy(s2);
91
1
                    }
92
310
                    flb_free(xml_val);
93
310
                }
94
310
            }
95
413
        }
96
564
    }
97
564
    if (format) {
98
564
        flb_free(format);
99
564
    }
100
564
    if (tag) {
101
564
        flb_free(tag);
102
564
    }
103
564
    if (tag_delimiter) {
104
564
        flb_free(tag_delimiter);
105
564
    }
106
564
    return 0;
107
641
}