Coverage Report

Created: 2026-06-15 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/fuzz/isc_lex_getmastertoken.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/string.h>
21
#include <isc/util.h>
22
23
#include "fuzz.h"
24
25
bool debug = false;
26
27
int
28
LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED);
29
30
int
31
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
32
33
static isc_mem_t *mctx = NULL;
34
static isc_lex_t *lex = NULL;
35
36
int
37
18
LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) {
38
18
  isc_mem_create("fuzz", &mctx);
39
18
  isc_lex_create(mctx, 1024, &lex);
40
41
18
  return 0;
42
18
}
43
44
int
45
1.00k
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
46
1.00k
  isc_buffer_t buf;
47
1.00k
  isc_result_t result;
48
1.00k
  isc_token_t token;
49
1.00k
  isc_tokentype_t expect;
50
1.00k
  bool eol;
51
52
1.00k
  if (size < sizeof(expect) + sizeof(eol)) {
53
4
    return 0;
54
4
  }
55
56
998
  (void)memmove(&expect, data, sizeof(expect));
57
998
  data += sizeof(expect);
58
998
  size -= sizeof(expect);
59
60
998
  eol = *data != 0;
61
998
  data += 1;
62
998
  size -= 1;
63
64
998
  isc_buffer_constinit(&buf, data, size);
65
998
  isc_buffer_add(&buf, size);
66
998
  isc_buffer_setactive(&buf, size);
67
68
998
  CHECK(isc_lex_openbuffer(lex, &buf));
69
70
20.6k
  do {
71
20.6k
    result = isc_lex_getmastertoken(lex, &token, expect, eol);
72
20.6k
  } while (result == ISC_R_SUCCESS && token.type != isc_tokentype_eof);
73
74
998
cleanup:
75
998
  return 0;
76
998
}