Coverage Report

Created: 2026-12-01 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/fuzz/dns_name_fromwire.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 <stdlib.h>
16
#include <unistd.h>
17
18
#include <isc/ascii.h>
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
26
#include "fuzz.h"
27
#include "old.h"
28
29
bool debug = false;
30
31
int
32
16
LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) {
33
16
  return 0;
34
16
}
35
36
int
37
204
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
38
204
  isc_result_t new_result;
39
204
  isc_result_t old_result;
40
204
  dns_fixedname_t new_fixed;
41
204
  dns_fixedname_t old_fixed;
42
204
  dns_name_t *new_name = dns_fixedname_initname(&new_fixed);
43
204
  dns_name_t *old_name = dns_fixedname_initname(&old_fixed);
44
204
  isc_buffer_t new_buf;
45
204
  isc_buffer_t old_buf;
46
204
  dns_decompress_t dctx = DNS_DECOMPRESS_INITIALIZER;
47
48
204
  dns_decompress_setpermitted(&dctx, true);
49
50
  /*
51
   * Output buffers may be partially used or undersized.
52
   */
53
204
  if (size > 0) {
54
204
    uint8_t add = *data++;
55
204
    size--;
56
204
    isc_buffer_add(&new_fixed.buffer, add);
57
204
    isc_buffer_add(&old_fixed.buffer, add);
58
204
  }
59
60
  /*
61
   * timeout faster if we hit a pointer loop
62
   */
63
204
  alarm(1);
64
65
  /*
66
   * We shift forward by half the input data to make an area
67
   * that pointers can refer back to.
68
   */
69
70
204
  isc_buffer_constinit(&new_buf, data, size);
71
204
  isc_buffer_add(&new_buf, size);
72
204
  isc_buffer_setactive(&new_buf, size);
73
204
  isc_buffer_forward(&new_buf, size / 2);
74
204
  dns_decompress_setbudget(&dctx, UINT32_MAX);
75
204
  new_result = dns_name_fromwire(new_name, &new_buf, &dctx, NULL);
76
77
204
  isc_buffer_constinit(&old_buf, data, size);
78
204
  isc_buffer_add(&old_buf, size);
79
204
  isc_buffer_setactive(&old_buf, size);
80
204
  isc_buffer_forward(&old_buf, size / 2);
81
204
  dns_decompress_setbudget(&dctx, UINT32_MAX);
82
204
  old_result = old_name_fromwire(old_name, &old_buf, &dctx, 0, NULL);
83
84
204
  REQUIRE(new_result == old_result);
85
204
  REQUIRE(dns_name_equal(new_name, old_name));
86
87
204
  REQUIRE(new_fixed.buffer.current == old_fixed.buffer.current);
88
204
  REQUIRE(new_fixed.buffer.active == old_fixed.buffer.active);
89
204
  REQUIRE(new_fixed.buffer.used == old_fixed.buffer.used);
90
204
  REQUIRE(new_fixed.buffer.length == old_fixed.buffer.length);
91
92
204
  REQUIRE(new_buf.base == old_buf.base);
93
204
  REQUIRE(new_buf.current == old_buf.current);
94
204
  REQUIRE(new_buf.active == old_buf.active);
95
204
  REQUIRE(new_buf.used == old_buf.used);
96
204
  REQUIRE(new_buf.length == old_buf.length);
97
98
204
  return 0;
99
204
}