Coverage Report

Created: 2026-02-09 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cjson_fuzzer.c
Line
Count
Source
1
// Copyright 2025 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
17
#include <stdint.h>
18
#include <stdlib.h>
19
#include <string.h>
20
#include "cjson.h"
21
22
1.49k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
23
    // cJSON_Parse expects a null-terminated string.
24
1.49k
    char *str = (char *)malloc(size + 1);
25
1.49k
    if (!str) {
26
0
        return 0;
27
0
    }
28
1.49k
    memcpy(str, data, size);
29
1.49k
    str[size] = '\0';
30
31
1.49k
    cJSON *json = cJSON_Parse(str);
32
1.49k
    if (json) {
33
505
        cJSON_Delete(json);
34
505
    }
35
36
1.49k
    free(str);
37
1.49k
    return 0;
38
1.49k
}