Coverage Report

Created: 2025-08-26 06:47

/src/inih/inihfuzz.c
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2024 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 <stdio.h>
18
#include <stdlib.h>
19
#include <string.h>
20
#include "ini.h"
21
22
1.12k
#define kMinInputLength 8
23
559
#define kMaxInputLength 512
24
25
int User;
26
char Prev_section[50];
27
28
int dumper(void* user, const char* section, const char* name,
29
           const char* value)
30
1.38k
{
31
1.38k
    User = *((int*)user);
32
1.38k
    if (strcmp(section, Prev_section)) {
33
380
        strncpy(Prev_section, section, sizeof(Prev_section));
34
380
        Prev_section[sizeof(Prev_section) - 1] = '\0';
35
380
    }
36
1.38k
    return 1;
37
1.38k
}
38
39
extern int
40
LLVMFuzzerTestOneInput(const char *data, size_t size)
41
563
{
42
563
    char *data_in;
43
563
    static int u = 100;
44
45
563
    if (size < kMinInputLength || size > kMaxInputLength) {
46
29
        return 0;
47
29
    }
48
49
534
    Prev_section[0] = '\0';
50
51
534
    data_in = calloc((size + 1), sizeof(char));
52
534
    if (!data_in) return 0;
53
54
534
    memcpy(data_in, data, size);
55
56
534
    ini_parse_string(data_in, dumper, &u);
57
58
534
    free(data_in);
59
60
534
    return 0;
61
534
}