Coverage Report

Created: 2026-08-09 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
315
        return -1;
33
315
    }
34
839
    flb_config_exit(config);
35
839
    return 0;
36
1.15k
}
37
38
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
39
585
{
40
585
    char *format = NULL;
41
585
    char *tag = NULL;
42
585
    char *tag_delimiter = NULL;
43
44
    /* Set flb_malloc_mod to be fuzzer-data dependent */
45
585
    if (size < 4) {
46
2
        return 0;
47
2
    }
48
583
    flb_malloc_p = 0;
49
583
    flb_malloc_mod = *(int*)data;
50
583
    data += 4;
51
583
    size -= 4;
52
53
    /* Avoid division by zero for modulo operations */
54
583
    if (flb_malloc_mod == 0) {
55
4
        flb_malloc_mod = 1;
56
4
    }
57
58
583
    if (size < 300) {
59
67
        return 0;
60
67
    }
61
62
516
    format = get_null_terminated(50, &data, &size);
63
516
    tag = get_null_terminated(100, &data, &size);
64
516
    tag_delimiter = get_null_terminated(100, &data, &size);
65
66
516
    struct tm day = { 0, 0, 0, 15, 7, 120};
67
516
    time_t t;
68
516
    memset(&t, 0, sizeof(time_t));
69
70
516
    if (format && tag && tag_delimiter) {
71
516
        if (!initialization_crutch()) {
72
361
            flb_sds_t s3_key_format = NULL;
73
361
            s3_key_format = flb_get_s3_key(format, t, tag, tag_delimiter, 0);
74
361
            if (s3_key_format) {
75
329
                flb_sds_destroy(s3_key_format);
76
329
            }
77
361
            if (size > 200) {
78
274
                char *json_val = get_null_terminated(100, &data, &size);
79
274
                if (json_val != NULL) {
80
274
                    flb_sds_t s1 = flb_aws_error(json_val, strlen(json_val));
81
274
                    if (s1 != NULL) {
82
1
                        flb_sds_destroy(s1);
83
1
                    }
84
274
                    flb_free(json_val);
85
274
                }
86
274
                char *xml_val = get_null_terminated(100, &data, &size);
87
274
                if (xml_val != NULL) {
88
274
                    flb_sds_t s2 = flb_aws_xml_error(xml_val, strlen(xml_val));
89
274
                    if (s2 != NULL) {
90
1
                        flb_sds_destroy(s2);
91
1
                    }
92
274
                    flb_free(xml_val);
93
274
                }
94
274
            }
95
361
        }
96
516
    }
97
516
    if (format) {
98
516
        flb_free(format);
99
516
    }
100
516
    if (tag) {
101
516
        flb_free(tag);
102
516
    }
103
516
    if (tag_delimiter) {
104
516
        flb_free(tag_delimiter);
105
516
    }
106
516
    return 0;
107
583
}