Coverage Report

Created: 2026-04-05 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/fuzz/dns_qpkey_name.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 <assert.h>
15
#include <stddef.h>
16
#include <stdint.h>
17
#include <string.h>
18
19
#include <isc/buffer.h>
20
#include <isc/util.h>
21
22
#include <dns/compress.h>
23
#include <dns/fixedname.h>
24
#include <dns/name.h>
25
#include <dns/qp.h>
26
27
#include "fuzz.h"
28
29
#include <tests/qp.h>
30
31
bool debug = false;
32
33
int
34
18
LLVMFuzzerInitialize(int *argc, char ***argv) {
35
18
  UNUSED(argc);
36
18
  UNUSED(argv);
37
18
  return 0;
38
18
}
39
40
int
41
545
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
42
545
  dns_fixedname_t fixedin, fixedout, fixedcmp;
43
545
  dns_name_t *namein, *nameout, *namecmp;
44
545
  isc_buffer_t buf;
45
545
  dns_qpkey_t key, cmp;
46
545
  dns_namespace_t space;
47
545
  isc_result_t result;
48
49
545
  namein = dns_fixedname_initname(&fixedin);
50
545
  nameout = dns_fixedname_initname(&fixedout);
51
545
  namecmp = dns_fixedname_initname(&fixedcmp);
52
53
545
  isc_buffer_constinit(&buf, data, size);
54
545
  isc_buffer_add(&buf, size);
55
545
  isc_buffer_setactive(&buf, size);
56
57
545
  CHECK(dns_name_fromwire(namein, &buf, DNS_DECOMPRESS_NEVER, NULL));
58
59
  /* verify round-trip conversion of first name */
60
506
  size_t keylen = dns_qpkey_fromname(key, namein, DNS_DBNAMESPACE_NORMAL);
61
506
  dns_qpkey_toname(key, keylen, nameout, &space);
62
63
506
  assert(dns_name_equal(namein, nameout));
64
506
  assert(space == DNS_DBNAMESPACE_NORMAL);
65
66
  /* is there a second name? */
67
506
  CHECK(dns_name_fromwire(namecmp, &buf, DNS_DECOMPRESS_NEVER, NULL));
68
69
361
  size_t cmplen = dns_qpkey_fromname(cmp, namecmp,
70
361
             DNS_DBNAMESPACE_NORMAL);
71
361
  size_t len = ISC_MIN(keylen, cmplen);
72
73
361
  int namerel = dns_name_compare(namein, namecmp);
74
361
  int keyrel = memcmp(key, cmp, len + 1);
75
76
361
  assert((namerel < 0) == (keyrel < 0));
77
361
  assert((namerel == 0) == (keyrel == 0));
78
361
  assert((namerel > 0) == (keyrel > 0));
79
361
  assert(space == DNS_DBNAMESPACE_NORMAL);
80
81
545
cleanup:
82
545
  return 0;
83
361
}