Coverage Report

Created: 2025-11-11 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/rdata/generic/nsec_47.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
/* RFC 3845 */
15
16
#ifndef RDATA_GENERIC_NSEC_47_C
17
#define RDATA_GENERIC_NSEC_47_C
18
19
/*
20
 * The attributes do not include DNS_RDATATYPEATTR_SINGLETON
21
 * because we must be able to handle a parent/child NSEC pair.
22
 */
23
#define RRTYPE_NSEC_ATTRIBUTES                                      \
24
16.7k
  (DNS_RDATATYPEATTR_DNSSEC | DNS_RDATATYPEATTR_ZONECUTAUTH | \
25
16.7k
   DNS_RDATATYPEATTR_ATCNAME)
26
27
static isc_result_t
28
9.19k
fromtext_nsec(ARGS_FROMTEXT) {
29
9.19k
  isc_token_t token;
30
9.19k
  isc_buffer_t buffer;
31
32
9.19k
  REQUIRE(type == dns_rdatatype_nsec);
33
34
9.19k
  UNUSED(type);
35
9.19k
  UNUSED(rdclass);
36
9.19k
  UNUSED(callbacks);
37
38
  /*
39
   * Next domain.
40
   */
41
9.19k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
42
9.19k
              false));
43
9.18k
  buffer_fromregion(&buffer, &token.value.as_region);
44
9.18k
  if (origin == NULL) {
45
885
    origin = dns_rootname;
46
885
  }
47
9.18k
  RETTOK(dns_name_wirefromtext(&buffer, origin, options, target));
48
49
9.18k
  return typemap_fromtext(lexer, target, false);
50
9.18k
}
51
52
static isc_result_t
53
2.46k
totext_nsec(ARGS_TOTEXT) {
54
2.46k
  isc_region_t sr;
55
2.46k
  dns_name_t name;
56
57
2.46k
  REQUIRE(rdata->type == dns_rdatatype_nsec);
58
2.46k
  REQUIRE(rdata->length != 0);
59
60
2.46k
  UNUSED(tctx);
61
62
2.46k
  dns_name_init(&name);
63
2.46k
  dns_rdata_toregion(rdata, &sr);
64
2.46k
  dns_name_fromregion(&name, &sr);
65
2.46k
  isc_region_consume(&sr, name_length(&name));
66
2.46k
  RETERR(dns_name_totext(&name, 0, target));
67
  /*
68
   * Don't leave a trailing space when there's no typemap present.
69
   */
70
2.46k
  if (sr.length > 0) {
71
2.46k
    RETERR(str_totext(" ", target));
72
2.46k
  }
73
2.46k
  return typemap_totext(&sr, NULL, target);
74
2.46k
}
75
76
static isc_result_t
77
3.01k
fromwire_nsec(ARGS_FROMWIRE) {
78
3.01k
  isc_region_t sr;
79
3.01k
  dns_name_t name;
80
81
3.01k
  REQUIRE(type == dns_rdatatype_nsec);
82
83
3.01k
  UNUSED(type);
84
3.01k
  UNUSED(rdclass);
85
86
3.01k
  dctx = dns_decompress_setpermitted(dctx, false);
87
88
3.01k
  dns_name_init(&name);
89
3.01k
  RETERR(dns_name_fromwire(&name, source, dctx, target));
90
91
2.93k
  isc_buffer_activeregion(source, &sr);
92
2.93k
  RETERR(typemap_test(&sr, false));
93
2.83k
  RETERR(mem_tobuffer(target, sr.base, sr.length));
94
2.75k
  isc_buffer_forward(source, sr.length);
95
2.75k
  return ISC_R_SUCCESS;
96
2.83k
}
97
98
static isc_result_t
99
1.24k
towire_nsec(ARGS_TOWIRE) {
100
1.24k
  isc_region_t sr;
101
1.24k
  dns_name_t name;
102
103
1.24k
  REQUIRE(rdata->type == dns_rdatatype_nsec);
104
1.24k
  REQUIRE(rdata->length != 0);
105
106
1.24k
  dns_compress_setpermitted(cctx, false);
107
1.24k
  dns_name_init(&name);
108
1.24k
  dns_rdata_toregion(rdata, &sr);
109
1.24k
  dns_name_fromregion(&name, &sr);
110
1.24k
  isc_region_consume(&sr, name_length(&name));
111
1.24k
  RETERR(dns_name_towire(&name, cctx, target));
112
113
1.24k
  return mem_tobuffer(target, sr.base, sr.length);
114
1.24k
}
115
116
static int
117
2.67k
compare_nsec(ARGS_COMPARE) {
118
2.67k
  isc_region_t r1;
119
2.67k
  isc_region_t r2;
120
121
2.67k
  REQUIRE(rdata1->type == rdata2->type);
122
2.67k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
123
2.67k
  REQUIRE(rdata1->type == dns_rdatatype_nsec);
124
2.67k
  REQUIRE(rdata1->length != 0);
125
2.67k
  REQUIRE(rdata2->length != 0);
126
127
2.67k
  dns_rdata_toregion(rdata1, &r1);
128
2.67k
  dns_rdata_toregion(rdata2, &r2);
129
2.67k
  return isc_region_compare(&r1, &r2);
130
2.67k
}
131
132
static isc_result_t
133
0
fromstruct_nsec(ARGS_FROMSTRUCT) {
134
0
  dns_rdata_nsec_t *nsec = source;
135
0
  isc_region_t region;
136
137
0
  REQUIRE(type == dns_rdatatype_nsec);
138
0
  REQUIRE(nsec != NULL);
139
0
  REQUIRE(nsec->common.rdtype == type);
140
0
  REQUIRE(nsec->common.rdclass == rdclass);
141
0
  REQUIRE(nsec->typebits != NULL || nsec->len == 0);
142
143
0
  UNUSED(type);
144
0
  UNUSED(rdclass);
145
146
0
  dns_name_toregion(&nsec->next, &region);
147
0
  RETERR(isc_buffer_copyregion(target, &region));
148
149
0
  region.base = nsec->typebits;
150
0
  region.length = nsec->len;
151
0
  RETERR(typemap_test(&region, false));
152
0
  return mem_tobuffer(target, nsec->typebits, nsec->len);
153
0
}
154
155
static isc_result_t
156
0
tostruct_nsec(ARGS_TOSTRUCT) {
157
0
  isc_region_t region;
158
0
  dns_rdata_nsec_t *nsec = target;
159
0
  dns_name_t name;
160
161
0
  REQUIRE(rdata->type == dns_rdatatype_nsec);
162
0
  REQUIRE(nsec != NULL);
163
0
  REQUIRE(rdata->length != 0);
164
165
0
  DNS_RDATACOMMON_INIT(nsec, rdata->type, rdata->rdclass);
166
167
0
  dns_name_init(&name);
168
0
  dns_rdata_toregion(rdata, &region);
169
0
  dns_name_fromregion(&name, &region);
170
0
  isc_region_consume(&region, name_length(&name));
171
0
  dns_name_init(&nsec->next);
172
0
  name_duporclone(&name, mctx, &nsec->next);
173
174
0
  nsec->len = region.length;
175
0
  nsec->typebits = mem_maybedup(mctx, region.base, region.length);
176
0
  nsec->mctx = mctx;
177
0
  return ISC_R_SUCCESS;
178
0
}
179
180
static void
181
0
freestruct_nsec(ARGS_FREESTRUCT) {
182
0
  dns_rdata_nsec_t *nsec = source;
183
184
0
  REQUIRE(nsec != NULL);
185
0
  REQUIRE(nsec->common.rdtype == dns_rdatatype_nsec);
186
187
0
  if (nsec->mctx == NULL) {
188
0
    return;
189
0
  }
190
191
0
  dns_name_free(&nsec->next, nsec->mctx);
192
0
  if (nsec->typebits != NULL) {
193
0
    isc_mem_free(nsec->mctx, nsec->typebits);
194
0
  }
195
0
  nsec->mctx = NULL;
196
0
}
197
198
static isc_result_t
199
0
additionaldata_nsec(ARGS_ADDLDATA) {
200
0
  REQUIRE(rdata->type == dns_rdatatype_nsec);
201
202
0
  UNUSED(rdata);
203
0
  UNUSED(owner);
204
0
  UNUSED(add);
205
0
  UNUSED(arg);
206
207
0
  return ISC_R_SUCCESS;
208
0
}
209
210
static isc_result_t
211
0
digest_nsec(ARGS_DIGEST) {
212
0
  isc_region_t r;
213
214
0
  REQUIRE(rdata->type == dns_rdatatype_nsec);
215
216
0
  dns_rdata_toregion(rdata, &r);
217
0
  return (digest)(arg, &r);
218
0
}
219
220
static bool
221
0
checkowner_nsec(ARGS_CHECKOWNER) {
222
0
  REQUIRE(type == dns_rdatatype_nsec);
223
224
0
  UNUSED(name);
225
0
  UNUSED(type);
226
0
  UNUSED(rdclass);
227
0
  UNUSED(wildcard);
228
229
0
  return true;
230
0
}
231
232
static bool
233
0
checknames_nsec(ARGS_CHECKNAMES) {
234
0
  REQUIRE(rdata->type == dns_rdatatype_nsec);
235
236
0
  UNUSED(rdata);
237
0
  UNUSED(owner);
238
0
  UNUSED(bad);
239
240
0
  return true;
241
0
}
242
243
static int
244
0
casecompare_nsec(ARGS_COMPARE) {
245
0
  isc_region_t region1;
246
0
  isc_region_t region2;
247
0
  dns_name_t name1;
248
0
  dns_name_t name2;
249
0
  int order;
250
251
0
  REQUIRE(rdata1->type == rdata2->type);
252
0
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
253
0
  REQUIRE(rdata1->type == dns_rdatatype_nsec);
254
0
  REQUIRE(rdata1->length != 0);
255
0
  REQUIRE(rdata2->length != 0);
256
257
0
  dns_name_init(&name1);
258
0
  dns_name_init(&name2);
259
260
0
  dns_rdata_toregion(rdata1, &region1);
261
0
  dns_rdata_toregion(rdata2, &region2);
262
263
0
  dns_name_fromregion(&name1, &region1);
264
0
  dns_name_fromregion(&name2, &region2);
265
266
0
  order = dns_name_rdatacompare(&name1, &name2);
267
0
  if (order != 0) {
268
0
    return order;
269
0
  }
270
271
0
  isc_region_consume(&region1, name_length(&name1));
272
0
  isc_region_consume(&region2, name_length(&name2));
273
274
0
  return isc_region_compare(&region1, &region2);
275
0
}
276
#endif /* RDATA_GENERIC_NSEC_47_C */