Coverage Report

Created: 2026-07-16 07:05

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
558
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
42
558
  dns_fixedname_t fixedin, fixedout, fixedcmp;
43
558
  dns_name_t *namein, *nameout, *namecmp;
44
558
  isc_buffer_t buf;
45
558
  dns_qpkey_t key, cmp;
46
558
  dns_namespace_t space;
47
558
  isc_result_t result;
48
49
558
  namein = dns_fixedname_initname(&fixedin);
50
558
  nameout = dns_fixedname_initname(&fixedout);
51
558
  namecmp = dns_fixedname_initname(&fixedcmp);
52
53
558
  isc_buffer_constinit(&buf, data, size);
54
558
  isc_buffer_add(&buf, size);
55
558
  isc_buffer_setactive(&buf, size);
56
57
558
  CHECK(dns_name_fromwire(namein, &buf, DNS_DECOMPRESS_NEVER, NULL));
58
59
  /* verify round-trip conversion of first name */
60
516
  size_t keylen = dns_qpkey_fromname(key, namein, DNS_DBNAMESPACE_NORMAL);
61
516
  dns_qpkey_toname(key, keylen, nameout, &space);
62
63
516
  assert(dns_name_equal(namein, nameout));
64
516
  assert(space == DNS_DBNAMESPACE_NORMAL);
65
66
  /* is there a second name? */
67
516
  CHECK(dns_name_fromwire(namecmp, &buf, DNS_DECOMPRESS_NEVER, NULL));
68
69
363
  size_t cmplen = dns_qpkey_fromname(cmp, namecmp,
70
363
             DNS_DBNAMESPACE_NORMAL);
71
363
  size_t len = ISC_MIN(keylen, cmplen);
72
73
363
  int namerel = dns_name_compare(namein, namecmp);
74
363
  int keyrel = memcmp(key, cmp, len + 1);
75
76
363
  assert((namerel < 0) == (keyrel < 0));
77
363
  assert((namerel == 0) == (keyrel == 0));
78
363
  assert((namerel > 0) == (keyrel > 0));
79
363
  assert(space == DNS_DBNAMESPACE_NORMAL);
80
81
558
cleanup:
82
558
  return 0;
83
363
}