Coverage Report

Created: 2026-02-09 07:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/tests/internal/fuzzers/signv4_fuzzer.c
Line
Count
Source
1
#include <fluent-bit/flb_info.h>
2
#include <fluent-bit/flb_mem.h>
3
#include <fluent-bit/flb_http_client.h>
4
#include <fluent-bit/flb_upstream.h>
5
#include <fluent-bit/flb_signv4.h>
6
#include <fluent-bit/flb_aws_credentials.h>
7
#include <monkey/mk_core.h>
8
#include <unistd.h>
9
#include <fluent-bit/flb_sds.h>
10
#include "flb_fuzz_header.h"
11
12
408
#define AWS_ACCESS_KEY_ID              "AWS_ACCESS_KEY_ID"
13
408
#define AWS_SECRET_ACCESS_KEY          "AWS_SECRET_ACCESS_KEY"
14
#define AWS_SESSION_TOKEN              "AWS_SESSION_TOKEN"
15
16
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
17
592
{
18
592
    if (size < 59) {
19
19
        return 0;
20
19
    }
21
22
    /* Set flb_malloc_mod to be fuzzer-data dependent */
23
573
    flb_malloc_p = 0;
24
573
    flb_malloc_mod = *(int*)data;
25
573
    data += 4;
26
573
    size -= 4;
27
28
    /* Avoid division by zero for modulo operations */
29
573
    if (flb_malloc_mod == 0) {
30
2
        flb_malloc_mod = 1;
31
2
    }
32
33
573
    char s3_mode = data[0];
34
573
    MOVE_INPUT(1)
35
573
    int method = (int)data[0];
36
37
    /* Prepare a general null-terminated string */
38
573
    char *uri             = get_null_terminated(50, &data, &size);
39
573
    char *null_terminated = get_null_terminated(size, &data, &size);
40
41
    /* Now begin the core work of the fuzzer */
42
573
    struct flb_config *config;
43
573
    struct mk_list *tests;
44
573
    struct flb_aws_provider *provider;
45
573
    config = flb_calloc(1, sizeof(struct flb_config));
46
573
    if (!config) {
47
3
        flb_free(uri);
48
3
        flb_free(null_terminated);
49
3
        return 0;
50
3
    }
51
570
    mk_list_init(&config->upstreams);
52
570
    provider = flb_aws_env_provider_create();
53
54
    /* Create the necessary http context */
55
570
    struct flb_upstream *http_u;
56
570
    struct flb_connection *http_u_conn = NULL;
57
570
    struct flb_http_client *http_c;
58
570
    struct flb_config *http_config;
59
60
570
    http_config = flb_config_init();
61
570
    if (http_config == NULL) {
62
154
        flb_aws_provider_destroy(provider);
63
154
        flb_free(uri);
64
154
        flb_free(null_terminated);
65
154
        flb_free(config);
66
154
        return 0;
67
154
    }
68
69
416
    http_u = flb_upstream_create(http_config, "127.0.0.1", 8001, 0, NULL);
70
416
    if (http_u != NULL) {
71
414
        http_u_conn = flb_calloc(1, sizeof(struct flb_connection));
72
414
        if (http_u_conn != NULL) {
73
413
            http_u_conn->upstream = http_u;
74
75
413
            http_c = flb_http_client(http_u_conn, method, uri,
76
413
                         null_terminated, size, "127.0.0.1", 8001, NULL, 0);
77
413
            if (http_c) {
78
                /* Call into the main target flb_signv4_do*/
79
408
                time_t t = 1440938160;
80
408
                char *region = "us-east-1";
81
408
                char *access_key = "AKIDEXAMPLE";
82
408
                char *service = "service";
83
408
                char *secret_key = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY";
84
408
                int ret = setenv(AWS_ACCESS_KEY_ID, access_key, 1);
85
408
                if (ret >= 0) {
86
408
                    ret = setenv(AWS_SECRET_ACCESS_KEY, secret_key, 1);
87
408
                    if (ret >= 0) {
88
408
                        flb_sds_t signature = flb_signv4_do(http_c, FLB_TRUE, FLB_FALSE,
89
408
                                    t, region, service, s3_mode, NULL, provider);
90
408
                        if (signature) {
91
324
                          flb_sds_destroy(signature);
92
324
                        }
93
408
                    }
94
408
                }
95
408
                flb_http_client_destroy(http_c);
96
408
            }
97
413
        }
98
414
        flb_upstream_destroy(http_u);
99
414
    }
100
101
    /* Cleanup */
102
416
    flb_config_exit(http_config);
103
416
    flb_aws_provider_destroy(provider);
104
416
    flb_free(config);
105
106
416
    flb_free(null_terminated);
107
416
    flb_free(http_u_conn);
108
416
    flb_free(uri);
109
110
416
    return 0;
111
570
}