Coverage Report

Created: 2026-01-17 06:14

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