Coverage Report

Created: 2025-07-18 07:03

/src/bind9/fuzz/isc_lex_gettoken.c
Line
Count
Source
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4
 * SPDX-License-Identifier: MPL-2.0
5
 *
6
 * This Source Code Form is subject to the terms of the Mozilla Public
7
 * License, v. 2.0. If a copy of the MPL was not distributed with this
8
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9
 *
10
 * See the COPYRIGHT file distributed with this work for additional
11
 * information regarding copyright ownership.
12
 */
13
14
#include <stddef.h>
15
#include <stdint.h>
16
17
#include <isc/buffer.h>
18
#include <isc/lex.h>
19
#include <isc/mem.h>
20
#include <isc/util.h>
21
22
#include "fuzz.h"
23
24
bool debug = false;
25
26
static isc_mem_t *mctx = NULL;
27
static isc_lex_t *lex = NULL;
28
29
int
30
18
LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) {
31
18
  isc_mem_create("fuzz", &mctx);
32
18
  isc_lex_create(mctx, 1024, &lex);
33
34
18
  return 0;
35
18
}
36
37
int
38
288
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
39
288
  isc_buffer_t buf;
40
288
  isc_result_t result;
41
42
288
  isc_buffer_constinit(&buf, data, size);
43
288
  isc_buffer_add(&buf, size);
44
288
  isc_buffer_setactive(&buf, size);
45
46
288
  CHECK(isc_lex_openbuffer(lex, &buf));
47
48
2.53k
  do {
49
2.53k
    isc_token_t token;
50
2.53k
    result = isc_lex_gettoken(lex, 0, &token);
51
2.53k
  } while (result == ISC_R_SUCCESS);
52
53
288
  return 0;
54
288
}