Coverage Report

Created: 2026-02-26 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/h3/src/apps/fuzzers/fuzzerIndexIO.c
Line
Count
Source
1
/*
2
 * Copyright 2021 Uber Technologies, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *         http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
/** @file
17
 * @brief Fuzzer program for h3ToString and stringToH3
18
 */
19
20
#include "aflHarness.h"
21
#include "h3api.h"
22
#include "utility.h"
23
24
40
#define STRING_LENGTH 32
25
26
typedef struct {
27
    H3Index index;
28
    char str[STRING_LENGTH];
29
} inputArgs;
30
31
30
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32
30
    if (size < sizeof(inputArgs)) {
33
10
        return 0;
34
10
    }
35
20
    inputArgs args;
36
    // Copy the input data array since we need to modify it on the next line
37
    // to ensure it is zero terminated. (We are not interested in non-zero
38
    // terminated bugs since that fails the contract.)
39
20
    memcpy(&args, data, sizeof(inputArgs));
40
20
    args.str[STRING_LENGTH - 1] = 0;
41
42
20
    char str[STRING_LENGTH];
43
20
    H3_EXPORT(h3ToString)(args.index, str, STRING_LENGTH);
44
20
    H3Index index;
45
20
    H3_EXPORT(stringToH3)(args.str, &index);
46
47
20
    return 0;
48
30
}
49
50
AFL_HARNESS_MAIN(sizeof(inputArgs));