Coverage Report

Created: 2026-12-01 06:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cjson/fuzzing/cjson_read_fuzzer.c
Line
Count
Source
1
#include <stdlib.h>
2
#include <stdint.h>
3
#include <string.h>
4
5
#ifdef __cplusplus
6
extern "C" {
7
#endif
8
9
#include "../cJSON.h"
10
11
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); /* required by C89 */
12
13
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
14
2.13k
{
15
2.13k
    cJSON *json;
16
2.13k
    size_t offset = 4;
17
2.13k
    unsigned char *copied;
18
2.13k
    char *printed_json = NULL;
19
2.13k
    int minify, require_termination, formatted, buffered;
20
21
22
2.13k
    if(size <= offset) return 0;
23
2.13k
    if(data[size-1] != '\0') return 0;
24
2.12k
    if(data[0] != '1' && data[0] != '0') return 0;
25
2.11k
    if(data[1] != '1' && data[1] != '0') return 0;
26
2.09k
    if(data[2] != '1' && data[2] != '0') return 0;
27
2.08k
    if(data[3] != '1' && data[3] != '0') return 0;
28
29
2.06k
    minify              = data[0] == '1' ? 1 : 0;
30
2.06k
    require_termination = data[1] == '1' ? 1 : 0;
31
2.06k
    formatted           = data[2] == '1' ? 1 : 0;
32
2.06k
    buffered            = data[3] == '1' ? 1 : 0;
33
34
2.06k
    json = cJSON_ParseWithOpts((const char*)data + offset, NULL, require_termination);
35
36
2.06k
    if(json == NULL) return 0;
37
38
1.10k
    if(buffered)
39
577
    {
40
577
        printed_json = cJSON_PrintBuffered(json, 1, formatted);
41
577
    }
42
528
    else
43
528
    {
44
        /* unbuffered printing */
45
528
        if(formatted)
46
245
        {
47
245
            printed_json = cJSON_Print(json);
48
245
        }
49
283
        else
50
283
        {
51
283
            printed_json = cJSON_PrintUnformatted(json);
52
283
        }
53
528
    }
54
55
1.10k
    if(printed_json != NULL) free(printed_json);
56
57
1.10k
    if(minify)
58
924
    {
59
924
        copied = (unsigned char*)malloc(size);
60
924
        if(copied == NULL) return 0;
61
62
924
        memcpy(copied, data, size);
63
64
924
        cJSON_Minify((char*)copied + offset);
65
66
924
        free(copied);
67
924
    }
68
69
1.10k
    cJSON_Delete(json);
70
71
1.10k
    return 0;
72
1.10k
}
73
74
#ifdef __cplusplus
75
}
76
#endif
77