Coverage Report

Created: 2026-11-12 07:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/tests/internal/fuzzers/flb_json_fuzzer.c
Line
Count
Source
1
/*  Fluent Bit
2
 *  ==========
3
 *  Copyright (C) 2019-2021 The Fluent Bit Authors
4
 *  Copyright (C) 2015-2018 Treasure Data Inc.
5
 *
6
 *  Licensed under the Apache License, Version 2.0 (the "License");
7
 *  you may not use this file except in compliance with the License.
8
 *  You may obtain a copy of the License at
9
 *
10
 *      http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *  Unless required by applicable law or agreed to in writing, software
13
 *  distributed under the License is distributed on an "AS IS" BASIS,
14
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *  See the License for the specific language governing permissions and
16
 *  limitations under the License.
17
 */
18
#include <stdlib.h>
19
#include <stdint.h>
20
#include <fluent-bit/flb_pack.h>
21
#include <fluent-bit/flb_str.h>
22
#include "flb_fuzz_header.h"
23
24
int LLVMFuzzerTestOneInput(unsigned char *data, size_t size)
25
24.4k
{
26
24.4k
    TIMEOUT_GUARD
27
    /* Set fuzzer-malloc chance of failure */
28
24.4k
    flb_malloc_p = 0;
29
24.4k
    flb_malloc_mod = 25000;
30
31
24.4k
    if (size < 1) {
32
0
        return 0;
33
0
    }
34
24.4k
    unsigned char decider = *data;
35
24.4k
    data++;
36
24.4k
    size--;
37
38
    /* json packer */
39
24.4k
    char *out_buf = NULL;
40
24.4k
    size_t out_size;
41
24.4k
    int root_type;
42
24.4k
    int ret = flb_pack_json((char*)data, size, &out_buf, &out_size, &root_type, NULL);
43
44
24.4k
    if (ret == 0) {
45
6.84k
        size_t off = 0;
46
6.84k
        msgpack_unpacked result;
47
6.84k
        msgpack_unpacked_init(&result);
48
6.84k
        int ret2 = msgpack_unpack_next(&result, out_buf, out_size, &off);
49
6.84k
        if (ret2 == MSGPACK_UNPACK_SUCCESS) {
50
6.81k
            msgpack_object root = result.data;
51
6.81k
            char *tmp = NULL;
52
6.81k
            tmp = flb_msgpack_to_json_str(0, &root, FLB_TRUE);
53
6.81k
            if (tmp != NULL) {
54
6.81k
                flb_free(tmp);
55
6.81k
            }
56
6.81k
        }
57
6.84k
        msgpack_unpacked_destroy(&result);
58
6.84k
        flb_sds_t d;
59
6.84k
        d = flb_sds_create("date");
60
6.84k
        if (decider < 0x30) {
61
3.68k
            flb_sds_t ret_s = flb_pack_msgpack_to_json_format(out_buf, out_size,
62
3.68k
                    FLB_PACK_JSON_FORMAT_LINES,
63
3.68k
                    (int)decider, d, FLB_TRUE);
64
3.68k
            free(out_buf);
65
3.68k
            if (ret_s != NULL) {
66
1.47k
                flb_sds_destroy(ret_s);
67
1.47k
            }
68
3.68k
        }
69
3.16k
        else {
70
3.16k
            flb_sds_t ret_s = flb_pack_msgpack_to_json_format(out_buf, out_size,
71
3.16k
                    FLB_PACK_JSON_FORMAT_LINES,
72
3.16k
                    FLB_PACK_JSON_DATE_EPOCH, NULL, FLB_TRUE);
73
3.16k
            free(out_buf);
74
3.16k
            if (ret_s != NULL) {
75
682
                flb_sds_destroy(ret_s);
76
682
            }
77
3.16k
        }
78
6.84k
        flb_sds_destroy(d);
79
6.84k
    }
80
81
24.4k
    return 0;
82
24.4k
}