1 /*
2 * testcode/unitdname.c - unit test for dname routines.
3 *
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
5 *
6 * This software is open source.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36 /**
37 * \file
38 * Calls dname unit tests. Exits with code 1 on a failure.
39 */
40
41 #include "config.h"
42 #include <ctype.h>
43 #include "util/log.h"
44 #include "testcode/unitmain.h"
45 #include "util/data/dname.h"
46 #include "sldns/sbuffer.h"
47 #include "sldns/str2wire.h"
48 #include "sldns/wire2str.h"
49
50 /** put dname into buffer */
51 static sldns_buffer*
dname_to_buf(sldns_buffer * b,const char * str)52 dname_to_buf(sldns_buffer* b, const char* str)
53 {
54 int e;
55 size_t len = sldns_buffer_capacity(b);
56 sldns_buffer_clear(b);
57 e = sldns_str2wire_dname_buf(str, sldns_buffer_begin(b), &len);
58 if(e != 0)
59 fatal_exit("%s ldns: %s", __func__,
60 sldns_get_errorstr_parse(e));
61 sldns_buffer_set_position(b, len);
62 sldns_buffer_flip(b);
63 return b;
64 }
65
66 /** test query_dname_len function */
67 static void
dname_test_qdl(sldns_buffer * buff)68 dname_test_qdl(sldns_buffer* buff)
69 {
70 unit_show_func("util/data/dname.c", "query_dname_len");
71 unit_assert( query_dname_len(buff) == 0);
72 unit_assert( query_dname_len(dname_to_buf(buff, ".")) == 1 );
73 unit_assert( query_dname_len(dname_to_buf(buff, "bla.foo.")) == 9 );
74 unit_assert( query_dname_len(dname_to_buf(buff, "x.y.z.example.com."
75 )) == 19 );
76 }
77
78 /** test query_dname_tolower */
79 static void
dname_test_qdtl(sldns_buffer * buff)80 dname_test_qdtl(sldns_buffer* buff)
81 {
82 unit_show_func("util/data/dname.c", "query_dname_tolower");
83 sldns_buffer_write_at(buff, 0, "\012abCDeaBCde\003cOm\000", 16);
84 query_dname_tolower(sldns_buffer_begin(buff));
85 unit_assert( memcmp(sldns_buffer_begin(buff),
86 "\012abcdeabcde\003com\000", 16) == 0);
87
88 sldns_buffer_write_at(buff, 0, "\001+\012abC{e-ZYXe\003NET\000", 18);
89 query_dname_tolower(sldns_buffer_begin(buff));
90 unit_assert( memcmp(sldns_buffer_begin(buff),
91 "\001+\012abc{e-zyxe\003net\000", 18) == 0);
92
93 sldns_buffer_write_at(buff, 0, "\000", 1);
94 query_dname_tolower(sldns_buffer_begin(buff));
95 unit_assert( memcmp(sldns_buffer_begin(buff), "\000", 1) == 0);
96
97 sldns_buffer_write_at(buff, 0, "\002NL\000", 4);
98 query_dname_tolower(sldns_buffer_begin(buff));
99 unit_assert( memcmp(sldns_buffer_begin(buff), "\002nl\000", 4) == 0);
100 }
101
102 /** test query_dname_compare */
103 static void
dname_test_query_dname_compare(void)104 dname_test_query_dname_compare(void)
105 {
106 unit_show_func("util/data/dname.c", "query_dname_compare");
107 unit_assert(query_dname_compare((uint8_t*)"", (uint8_t*)"") == 0);
108 unit_assert(query_dname_compare((uint8_t*)"\001a",
109 (uint8_t*)"\001a") == 0);
110 unit_assert(query_dname_compare((uint8_t*)"\003abc\001a",
111 (uint8_t*)"\003abc\001a") == 0);
112 unit_assert(query_dname_compare((uint8_t*)"\003aBc\001a",
113 (uint8_t*)"\003AbC\001A") == 0);
114 unit_assert(query_dname_compare((uint8_t*)"\003abc",
115 (uint8_t*)"\003abc\001a") == -1);
116 unit_assert(query_dname_compare((uint8_t*)"\003abc\001a",
117 (uint8_t*)"\003abc") == +1);
118 unit_assert(query_dname_compare((uint8_t*)"\003abc\001a",
119 (uint8_t*)"") == +1);
120 unit_assert(query_dname_compare((uint8_t*)"",
121 (uint8_t*)"\003abc\001a") == -1);
122 unit_assert(query_dname_compare((uint8_t*)"\003abc\001a",
123 (uint8_t*)"\003xxx\001a") == -1);
124 unit_assert(query_dname_compare((uint8_t*)"\003axx\001a",
125 (uint8_t*)"\003abc\001a") == 1);
126 unit_assert(query_dname_compare((uint8_t*)"\003abc\001a",
127 (uint8_t*)"\003abc\001Z") == -1);
128 unit_assert(query_dname_compare((uint8_t*)"\003abc\001Z",
129 (uint8_t*)"\003abc\001a") == 1);
130 }
131
132 /** test dname_count_labels */
133 static void
dname_test_count_labels(void)134 dname_test_count_labels(void)
135 {
136 unit_show_func("util/data/dname.c", "dname_count_labels");
137 unit_assert(dname_count_labels((uint8_t*)"") == 1);
138 unit_assert(dname_count_labels((uint8_t*)"\003com") == 2);
139 unit_assert(dname_count_labels((uint8_t*)"\003org") == 2);
140 unit_assert(dname_count_labels((uint8_t*)"\007example\003com") == 3);
141 unit_assert(dname_count_labels((uint8_t*)"\003bla\007example\003com")
142 == 4);
143 }
144
145 /** test dname_count_size_labels */
146 static void
dname_test_count_size_labels(void)147 dname_test_count_size_labels(void)
148 {
149 size_t sz = 0;
150 unit_show_func("util/data/dname.c", "dname_count_size_labels");
151 unit_assert(dname_count_size_labels((uint8_t*)"", &sz) == 1);
152 unit_assert(sz == 1);
153 unit_assert(dname_count_size_labels((uint8_t*)"\003com", &sz) == 2);
154 unit_assert(sz == 5);
155 unit_assert(dname_count_size_labels((uint8_t*)"\003org", &sz) == 2);
156 unit_assert(sz == 5);
157 unit_assert(dname_count_size_labels((uint8_t*)"\007example\003com",
158 &sz) == 3);
159 unit_assert(sz == 13);
160 unit_assert(dname_count_size_labels((uint8_t*)"\003bla\007example"
161 "\003com", &sz) == 4);
162 unit_assert(sz == 17);
163 }
164
165
166 /** test pkt_dname_len */
167 static void
dname_test_pkt_dname_len(sldns_buffer * buff)168 dname_test_pkt_dname_len(sldns_buffer* buff)
169 {
170 unit_show_func("util/data/dname.c", "pkt_dname_len");
171 sldns_buffer_clear(buff);
172 sldns_buffer_write(buff, "\000", 1);
173 sldns_buffer_flip(buff);
174 unit_assert( pkt_dname_len(buff) == 1 );
175 unit_assert( sldns_buffer_position(buff) == 1);
176
177 sldns_buffer_clear(buff);
178 sldns_buffer_write(buff, "\003org\000", 5);
179 sldns_buffer_flip(buff);
180 unit_assert( pkt_dname_len(buff) == 5 );
181 unit_assert( sldns_buffer_position(buff) == 5);
182
183 sldns_buffer_clear(buff);
184 sldns_buffer_write(buff, "\002os\007example\003org\000", 16);
185 sldns_buffer_flip(buff);
186 unit_assert( pkt_dname_len(buff) == 16 );
187 unit_assert( sldns_buffer_position(buff) == 16);
188
189 /* invalid compression pointer: to self */
190 sldns_buffer_clear(buff);
191 sldns_buffer_write(buff, "\300\000os\007example\003org\000", 17);
192 sldns_buffer_flip(buff);
193 unit_assert( pkt_dname_len(buff) == 0 );
194
195 /* valid compression pointer */
196 sldns_buffer_clear(buff);
197 sldns_buffer_write(buff, "\003com\000\040\300\000", 8);
198 sldns_buffer_flip(buff);
199 sldns_buffer_set_position(buff, 6);
200 unit_assert( pkt_dname_len(buff) == 5 );
201 unit_assert( sldns_buffer_position(buff) == 8);
202
203 /* unknown label type */
204 sldns_buffer_clear(buff);
205 sldns_buffer_write(buff, "\002os\107example\003org\000", 16);
206 sldns_buffer_flip(buff);
207 unit_assert( pkt_dname_len(buff) == 0 );
208
209 /* label too long */
210 sldns_buffer_clear(buff);
211 sldns_buffer_write(buff, "\002os\047example\003org\000", 16);
212 sldns_buffer_flip(buff);
213 unit_assert( pkt_dname_len(buff) == 0 );
214
215 /* label exceeds packet */
216 sldns_buffer_clear(buff);
217 sldns_buffer_write(buff, "\002os\007example\007org\004", 16);
218 sldns_buffer_flip(buff);
219 unit_assert( pkt_dname_len(buff) == 0 );
220
221 /* name very long */
222 sldns_buffer_clear(buff);
223 sldns_buffer_write(buff,
224 "\020a1cdef5555544444"
225 "\020a2cdef5555544444"
226 "\020a3cdef5555544444"
227 "\020a4cdef5555544444"
228 "\020a5cdef5555544444"
229 "\020a6cdef5555544444"
230 "\020a7cdef5555544444"
231 "\020a8cdef5555544444"
232 "\020a9cdef5555544444"
233 "\020aAcdef5555544444"
234 "\020aBcdef5555544444"
235 "\020aCcdef5555544444"
236 "\020aDcdef5555544444"
237 "\020aEcdef5555544444" /* 238 up to here */
238 "\007aabbccd" /* 246 up to here */
239 "\007example\000" /* 255 to here */
240 , 255);
241 sldns_buffer_flip(buff);
242 unit_assert( pkt_dname_len(buff) == 255 );
243 unit_assert( sldns_buffer_position(buff) == 255);
244
245 /* name too long */
246 sldns_buffer_clear(buff);
247 sldns_buffer_write(buff,
248 "\020a1cdef5555544444"
249 "\020a2cdef5555544444"
250 "\020a3cdef5555544444"
251 "\020a4cdef5555544444"
252 "\020a5cdef5555544444"
253 "\020a6cdef5555544444"
254 "\020a7cdef5555544444"
255 "\020a8cdef5555544444"
256 "\020a9cdef5555544444"
257 "\020aAcdef5555544444"
258 "\020aBcdef5555544444"
259 "\020aCcdef5555544444"
260 "\020aXcdef5555544444"
261 "\020aXcdef5555544444"
262 "\020aXcdef5555544444"
263 "\020aDcdef5555544444"
264 "\020aEcdef5555544444" /* 238 up to here */
265 "\007aabbccd" /* 246 up to here */
266 "\007example\000" /* 255 to here */
267 , 255);
268 sldns_buffer_flip(buff);
269 unit_assert( pkt_dname_len(buff) == 0 );
270 }
271
272 /** test dname_lab_cmp */
273 static void
dname_test_dname_lab_cmp(void)274 dname_test_dname_lab_cmp(void)
275 {
276 int ml = 0; /* number of labels that matched exactly */
277 unit_show_func("util/data/dname.c", "dname_lab_cmp");
278
279 /* test for equality succeeds */
280 unit_assert(dname_lab_cmp((uint8_t*)"", 1, (uint8_t*)"", 1, &ml) == 0);
281 unit_assert(ml == 1);
282 unit_assert(dname_lab_cmp(
283 (uint8_t*)"\003net", 2,
284 (uint8_t*)"\003net", 2,
285 &ml) == 0);
286 unit_assert(ml == 2);
287 unit_assert(dname_lab_cmp(
288 (uint8_t*)"\007example\003net", 3,
289 (uint8_t*)"\007example\003net", 3,
290 &ml) == 0);
291 unit_assert(ml == 3);
292 unit_assert(dname_lab_cmp(
293 (uint8_t*)"\004test\007example\003net", 4,
294 (uint8_t*)"\004test\007example\003net", 4,
295 &ml) == 0);
296 unit_assert(ml == 4);
297
298 /* root is smaller than anything else */
299 unit_assert(dname_lab_cmp(
300 (uint8_t*)"", 1,
301 (uint8_t*)"\003net", 2,
302 &ml) == -1);
303 unit_assert(ml == 1);
304 unit_assert(dname_lab_cmp(
305 (uint8_t*)"\003net", 2,
306 (uint8_t*)"", 1,
307 &ml) == 1);
308 unit_assert(ml == 1);
309 unit_assert(dname_lab_cmp(
310 (uint8_t*)"", 1,
311 (uint8_t*)"\007example\003net", 3,
312 &ml) == -1);
313 unit_assert(ml == 1);
314 unit_assert(dname_lab_cmp(
315 (uint8_t*)"\007example\003net", 3,
316 (uint8_t*)"", 1,
317 &ml) == 1);
318 unit_assert(ml == 1);
319
320 /* label length makes a difference */
321 unit_assert(dname_lab_cmp(
322 (uint8_t*)"\004neta", 2,
323 (uint8_t*)"\003net", 2,
324 &ml) != 0);
325 unit_assert(ml == 1);
326 unit_assert(dname_lab_cmp(
327 (uint8_t*)"\002ne", 2,
328 (uint8_t*)"\004neta", 2,
329 &ml) != 0);
330 unit_assert(ml == 1);
331
332 /* contents follow the zone apex */
333 unit_assert(dname_lab_cmp(
334 (uint8_t*)"\003bla\007example\003net", 4,
335 (uint8_t*)"\007example\003net", 3,
336 &ml) == 1);
337 unit_assert(ml == 3);
338 unit_assert(dname_lab_cmp(
339 (uint8_t*)"\007example\003net", 3,
340 (uint8_t*)"\003bla\007example\003net", 4,
341 &ml) == -1);
342 unit_assert(ml == 3);
343
344 /* label content makes a difference */
345 unit_assert(dname_lab_cmp(
346 (uint8_t*)"\003aag\007example\003net", 4,
347 (uint8_t*)"\003bla\007example\003net", 4,
348 &ml) == -1);
349 unit_assert(ml == 3);
350 unit_assert(dname_lab_cmp(
351 (uint8_t*)"\003aag\007example\003net", 4,
352 (uint8_t*)"\003bla\007example\003net", 4,
353 &ml) == -1);
354 unit_assert(ml == 3);
355 unit_assert(dname_lab_cmp(
356 (uint8_t*)"\003bla\003aag\007example\003net", 5,
357 (uint8_t*)"\003aag\003bla\007example\003net", 5,
358 &ml) == -1);
359 unit_assert(ml == 3);
360 unit_assert(dname_lab_cmp(
361 (uint8_t*)"\02sn\003opt\003aag\007example\003net", 6,
362 (uint8_t*)"\02sn\003opt\003bla\007example\003net", 6,
363 &ml) == -1);
364 unit_assert(ml == 3);
365
366 /* but lowercase/uppercase does not make a difference. */
367 unit_assert(dname_lab_cmp(
368 (uint8_t*)"\003bLa\007examPLe\003net", 4,
369 (uint8_t*)"\003bla\007eXAmple\003nET", 4,
370 &ml) == 0);
371 unit_assert(ml == 4);
372 }
373
374 /** test dname_subdomain_c */
375 static void
dname_test_subdomain(void)376 dname_test_subdomain(void)
377 {
378 unit_show_func("util/data/dname.c", "dname_subdomain");
379 unit_assert(dname_subdomain_c(
380 (uint8_t*)"",
381 (uint8_t*)""));
382 unit_assert(dname_subdomain_c(
383 (uint8_t*)"\003com",
384 (uint8_t*)""));
385 unit_assert(!dname_subdomain_c(
386 (uint8_t*)"",
387 (uint8_t*)"\003com"));
388 unit_assert(dname_subdomain_c(
389 (uint8_t*)"\007example\003com",
390 (uint8_t*)"\003com"));
391 unit_assert(!dname_subdomain_c(
392 (uint8_t*)"\003com",
393 (uint8_t*)"\007example\003com"));
394 unit_assert(dname_subdomain_c(
395 (uint8_t*)"\007example\003com",
396 (uint8_t*)""));
397 unit_assert(!dname_subdomain_c(
398 (uint8_t*)"\003net",
399 (uint8_t*)"\003com"));
400 unit_assert(!dname_subdomain_c(
401 (uint8_t*)"\003net",
402 (uint8_t*)"\003org"));
403 unit_assert(!dname_subdomain_c(
404 (uint8_t*)"\007example\003net",
405 (uint8_t*)"\003org"));
406 unit_assert(!dname_subdomain_c(
407 (uint8_t*)"\003net",
408 (uint8_t*)"\007example\003org"));
409 }
410
411 /** test dname_strict_subdomain */
412 static void
dname_test_strict_subdomain(void)413 dname_test_strict_subdomain(void)
414 {
415 unit_show_func("util/data/dname.c", "dname_strict_subdomain");
416 unit_assert(!dname_strict_subdomain(
417 (uint8_t*)"", 1,
418 (uint8_t*)"", 1));
419 unit_assert(dname_strict_subdomain(
420 (uint8_t*)"\003com", 2,
421 (uint8_t*)"", 1));
422 unit_assert(!dname_strict_subdomain(
423 (uint8_t*)"", 1,
424 (uint8_t*)"\003com", 2));
425 unit_assert(dname_strict_subdomain(
426 (uint8_t*)"\007example\003com", 3,
427 (uint8_t*)"\003com", 2));
428 unit_assert(!dname_strict_subdomain(
429 (uint8_t*)"\003com", 2,
430 (uint8_t*)"\007example\003com", 3));
431 unit_assert(dname_strict_subdomain(
432 (uint8_t*)"\007example\003com", 3,
433 (uint8_t*)"", 1));
434 unit_assert(!dname_strict_subdomain(
435 (uint8_t*)"\003net", 2,
436 (uint8_t*)"\003com", 2));
437 unit_assert(!dname_strict_subdomain(
438 (uint8_t*)"\003net", 2,
439 (uint8_t*)"\003org", 2));
440 unit_assert(!dname_strict_subdomain(
441 (uint8_t*)"\007example\003net", 3,
442 (uint8_t*)"\003org", 2));
443 unit_assert(!dname_strict_subdomain(
444 (uint8_t*)"\003net", 2,
445 (uint8_t*)"\007example\003org", 3));
446 }
447
448 /** test dname_is_root */
449 static void
dname_test_isroot(void)450 dname_test_isroot(void)
451 {
452 unit_show_func("util/data/dname.c", "dname_isroot");
453 unit_assert(dname_is_root((uint8_t*)"\000"));
454 unit_assert(!dname_is_root((uint8_t*)"\001a\000"));
455 unit_assert(!dname_is_root((uint8_t*)"\005abvcd\003com\000"));
456 /* malformed dname in this test, but should work */
457 unit_assert(!dname_is_root((uint8_t*)"\077a\000"));
458 unit_assert(dname_is_root((uint8_t*)"\000"));
459 }
460
461 /** test dname_remove_label */
462 static void
dname_test_removelabel(void)463 dname_test_removelabel(void)
464 {
465 uint8_t* orig = (uint8_t*)"\007example\003com\000";
466 uint8_t* n = orig;
467 size_t l = 13;
468 unit_show_func("util/data/dname.c", "dname_remove_label");
469 dname_remove_label(&n, &l);
470 unit_assert( n == orig+8 );
471 unit_assert( l == 5 );
472 dname_remove_label(&n, &l);
473 unit_assert( n == orig+12 );
474 unit_assert( l == 1 );
475 dname_remove_label(&n, &l);
476 unit_assert( n == orig+12 );
477 unit_assert( l == 1 );
478 }
479
480 /** test dname_remove_label_limit_len */
481 static void
dname_test_removelabellimitlen(void)482 dname_test_removelabellimitlen(void)
483 {
484 uint8_t* orig = (uint8_t*)"\007example\003com\000";
485 uint8_t* n = orig;
486 size_t l = 13;
487 size_t lenlimit = 5; /* com.*/
488 unit_show_func("util/data/dname.c", "dname_remove_label_limit_len");
489 unit_assert(dname_remove_label_limit_len(&n, &l, lenlimit) == 1);
490 unit_assert( n == orig+8 );
491 unit_assert( l == 5 );
492 unit_assert(dname_remove_label_limit_len(&n, &l, lenlimit) == 0);
493 unit_assert( n == orig+8 );
494 unit_assert( l == 5 );
495 }
496
497 /** test dname_signame_label_count */
498 static void
dname_test_sigcount(void)499 dname_test_sigcount(void)
500 {
501 unit_show_func("util/data/dname.c", "dname_signame_label_count");
502 unit_assert(dname_signame_label_count((uint8_t*)"\000") == 0);
503 unit_assert(dname_signame_label_count((uint8_t*)"\001*\000") == 0);
504 unit_assert(dname_signame_label_count((uint8_t*)"\003xom\000") == 1);
505 unit_assert(dname_signame_label_count(
506 (uint8_t*)"\001*\003xom\000") == 1);
507 unit_assert(dname_signame_label_count(
508 (uint8_t*)"\007example\003xom\000") == 2);
509 unit_assert(dname_signame_label_count(
510 (uint8_t*)"\001*\007example\003xom\000") == 2);
511 unit_assert(dname_signame_label_count(
512 (uint8_t*)"\003www\007example\003xom\000") == 3);
513 unit_assert(dname_signame_label_count(
514 (uint8_t*)"\001*\003www\007example\003xom\000") == 3);
515 }
516
517 /** test dname_is_wild routine */
518 static void
dname_test_iswild(void)519 dname_test_iswild(void)
520 {
521 unit_show_func("util/data/dname.c", "dname_iswild");
522 unit_assert( !dname_is_wild((uint8_t*)"\000") );
523 unit_assert( dname_is_wild((uint8_t*)"\001*\000") );
524 unit_assert( !dname_is_wild((uint8_t*)"\003net\000") );
525 unit_assert( dname_is_wild((uint8_t*)"\001*\003net\000") );
526 }
527
528 /** test dname_canonical_compare */
529 static void
dname_test_canoncmp(void)530 dname_test_canoncmp(void)
531 {
532 unit_show_func("util/data/dname.c", "dname_canonical_compare");
533 /* equality */
534 unit_assert( dname_canonical_compare(
535 (uint8_t*)"\000",
536 (uint8_t*)"\000"
537 ) == 0);
538 unit_assert( dname_canonical_compare(
539 (uint8_t*)"\003net\000",
540 (uint8_t*)"\003net\000"
541 ) == 0);
542 unit_assert( dname_canonical_compare(
543 (uint8_t*)"\007example\003net\000",
544 (uint8_t*)"\007example\003net\000"
545 ) == 0);
546 unit_assert( dname_canonical_compare(
547 (uint8_t*)"\004test\007example\003net\000",
548 (uint8_t*)"\004test\007example\003net\000"
549 ) == 0);
550
551 /* subdomains */
552 unit_assert( dname_canonical_compare(
553 (uint8_t*)"\003com",
554 (uint8_t*)"\000"
555 ) == 1);
556 unit_assert( dname_canonical_compare(
557 (uint8_t*)"\000",
558 (uint8_t*)"\003com"
559 ) == -1);
560 unit_assert( dname_canonical_compare(
561 (uint8_t*)"\007example\003com",
562 (uint8_t*)"\003com"
563 ) == 1);
564 unit_assert( dname_canonical_compare(
565 (uint8_t*)"\003com",
566 (uint8_t*)"\007example\003com"
567 ) == -1);
568 unit_assert( dname_canonical_compare(
569 (uint8_t*)"\007example\003com",
570 (uint8_t*)"\000"
571 ) == 1);
572 unit_assert( dname_canonical_compare(
573 (uint8_t*)"\000",
574 (uint8_t*)"\007example\003com"
575 ) == -1);
576
577 /* compare rightmost label */
578 unit_assert( dname_canonical_compare(
579 (uint8_t*)"\003com",
580 (uint8_t*)"\003net"
581 ) == -1);
582 unit_assert( dname_canonical_compare(
583 (uint8_t*)"\003net",
584 (uint8_t*)"\003com"
585 ) == 1);
586 unit_assert( dname_canonical_compare(
587 (uint8_t*)"\003net",
588 (uint8_t*)"\003org"
589 ) == -1);
590 unit_assert( dname_canonical_compare(
591 (uint8_t*)"\007example\003net",
592 (uint8_t*)"\003org"
593 ) == -1);
594 unit_assert( dname_canonical_compare(
595 (uint8_t*)"\003org",
596 (uint8_t*)"\007example\003net"
597 ) == 1);
598
599 /* label length makes a difference; but only if rest is equal */
600 unit_assert( dname_canonical_compare(
601 (uint8_t*)"\004neta",
602 (uint8_t*)"\003net"
603 ) == 1);
604 unit_assert( dname_canonical_compare(
605 (uint8_t*)"\002ne",
606 (uint8_t*)"\004neta"
607 ) == -1);
608
609 /* label content */
610 unit_assert( dname_canonical_compare(
611 (uint8_t*)"\003aag\007example\003net",
612 (uint8_t*)"\003bla\007example\003net"
613 ) == -1);
614 unit_assert( dname_canonical_compare(
615 (uint8_t*)"\003bla\007example\003net",
616 (uint8_t*)"\003aag\007example\003net"
617 ) == 1);
618 unit_assert( dname_canonical_compare(
619 (uint8_t*)"\003bla\003aag\007example\003net",
620 (uint8_t*)"\003aag\003bla\007example\003net"
621 ) == -1);
622 unit_assert( dname_canonical_compare(
623 (uint8_t*)"\02sn\003opt\003aag\007example\003net",
624 (uint8_t*)"\02sn\003opt\003bla\007example\003net"
625 ) == -1);
626
627 /* lowercase during compare */
628 unit_assert( dname_canonical_compare(
629 (uint8_t*)"\003bLa\007examPLe\003net",
630 (uint8_t*)"\003bla\007eXAmple\003nET"
631 ) == 0);
632
633 /* example from 4034 */
634 /* example a.example yljkjljk.a.example Z.a.example zABC.a.EXAMPLE
635 z.example \001.z.example *.z.example \200.z.example */
636 unit_assert( dname_canonical_compare(
637 (uint8_t*)"",
638 (uint8_t*)"\007example"
639 ) == -1);
640 unit_assert( dname_canonical_compare(
641 (uint8_t*)"\007example",
642 (uint8_t*)"\001a\007example"
643 ) == -1);
644 unit_assert( dname_canonical_compare(
645 (uint8_t*)"\001a\007example",
646 (uint8_t*)"\010yljkjljk\001a\007example"
647 ) == -1);
648 unit_assert( dname_canonical_compare(
649 (uint8_t*)"\010yljkjljk\001a\007example",
650 (uint8_t*)"\001Z\001a\007example"
651 ) == -1);
652 unit_assert( dname_canonical_compare(
653 (uint8_t*)"\001Z\001a\007example",
654 (uint8_t*)"\004zABC\001a\007EXAMPLE"
655 ) == -1);
656 unit_assert( dname_canonical_compare(
657 (uint8_t*)"\004zABC\001a\007EXAMPLE",
658 (uint8_t*)"\001z\007example"
659 ) == -1);
660 unit_assert( dname_canonical_compare(
661 (uint8_t*)"\001z\007example",
662 (uint8_t*)"\001\001\001z\007example"
663 ) == -1);
664 unit_assert( dname_canonical_compare(
665 (uint8_t*)"\001\001\001z\007example",
666 (uint8_t*)"\001*\001z\007example"
667 ) == -1);
668 unit_assert( dname_canonical_compare(
669 (uint8_t*)"\001*\001z\007example",
670 (uint8_t*)"\001\200\001z\007example"
671 ) == -1);
672 /* same example in reverse */
673 unit_assert( dname_canonical_compare(
674 (uint8_t*)"\007example",
675 (uint8_t*)""
676 ) == 1);
677 unit_assert( dname_canonical_compare(
678 (uint8_t*)"\001a\007example",
679 (uint8_t*)"\007example"
680 ) == 1);
681 unit_assert( dname_canonical_compare(
682 (uint8_t*)"\010yljkjljk\001a\007example",
683 (uint8_t*)"\001a\007example"
684 ) == 1);
685 unit_assert( dname_canonical_compare(
686 (uint8_t*)"\001Z\001a\007example",
687 (uint8_t*)"\010yljkjljk\001a\007example"
688 ) == 1);
689 unit_assert( dname_canonical_compare(
690 (uint8_t*)"\004zABC\001a\007EXAMPLE",
691 (uint8_t*)"\001Z\001a\007example"
692 ) == 1);
693 unit_assert( dname_canonical_compare(
694 (uint8_t*)"\001z\007example",
695 (uint8_t*)"\004zABC\001a\007EXAMPLE"
696 ) == 1);
697 unit_assert( dname_canonical_compare(
698 (uint8_t*)"\001\001\001z\007example",
699 (uint8_t*)"\001z\007example"
700 ) == 1);
701 unit_assert( dname_canonical_compare(
702 (uint8_t*)"\001*\001z\007example",
703 (uint8_t*)"\001\001\001z\007example"
704 ) == 1);
705 unit_assert( dname_canonical_compare(
706 (uint8_t*)"\001\200\001z\007example",
707 (uint8_t*)"\001*\001z\007example"
708 ) == 1);
709 /* same example for equality */
710 unit_assert( dname_canonical_compare(
711 (uint8_t*)"\007example",
712 (uint8_t*)"\007example"
713 ) == 0);
714 unit_assert( dname_canonical_compare(
715 (uint8_t*)"\001a\007example",
716 (uint8_t*)"\001a\007example"
717 ) == 0);
718 unit_assert( dname_canonical_compare(
719 (uint8_t*)"\010yljkjljk\001a\007example",
720 (uint8_t*)"\010yljkjljk\001a\007example"
721 ) == 0);
722 unit_assert( dname_canonical_compare(
723 (uint8_t*)"\001Z\001a\007example",
724 (uint8_t*)"\001Z\001a\007example"
725 ) == 0);
726 unit_assert( dname_canonical_compare(
727 (uint8_t*)"\004zABC\001a\007EXAMPLE",
728 (uint8_t*)"\004zABC\001a\007EXAMPLE"
729 ) == 0);
730 unit_assert( dname_canonical_compare(
731 (uint8_t*)"\001z\007example",
732 (uint8_t*)"\001z\007example"
733 ) == 0);
734 unit_assert( dname_canonical_compare(
735 (uint8_t*)"\001\001\001z\007example",
736 (uint8_t*)"\001\001\001z\007example"
737 ) == 0);
738 unit_assert( dname_canonical_compare(
739 (uint8_t*)"\001*\001z\007example",
740 (uint8_t*)"\001*\001z\007example"
741 ) == 0);
742 unit_assert( dname_canonical_compare(
743 (uint8_t*)"\001\200\001z\007example",
744 (uint8_t*)"\001\200\001z\007example"
745 ) == 0);
746 }
747
748 /** Test dname_get_shared_topdomain */
749 static void
dname_test_topdomain(void)750 dname_test_topdomain(void)
751 {
752 unit_show_func("util/data/dname.c", "dname_get_shared_topdomain");
753 unit_assert( query_dname_compare(
754 dname_get_shared_topdomain(
755 (uint8_t*)"",
756 (uint8_t*)""),
757 (uint8_t*)"") == 0);
758 unit_assert( query_dname_compare(
759 dname_get_shared_topdomain(
760 (uint8_t*)"\003www\007example\003com",
761 (uint8_t*)"\003www\007example\003com"),
762 (uint8_t*)"\003www\007example\003com") == 0);
763 unit_assert( query_dname_compare(
764 dname_get_shared_topdomain(
765 (uint8_t*)"\003www\007example\003com",
766 (uint8_t*)"\003bla\007example\003com"),
767 (uint8_t*)"\007example\003com") == 0);
768 }
769
770 /** Test dname_valid */
771 static void
dname_test_valid(void)772 dname_test_valid(void)
773 {
774 unit_show_func("util/data/dname.c", "dname_valid");
775 unit_assert( dname_valid(
776 (uint8_t*)"\003www\007example\003com", 255) == 17);
777 unit_assert( dname_valid((uint8_t*)"", 255) == 1);
778 unit_assert( dname_valid( (uint8_t*)
779 "\020a1cdef5555544444"
780 "\020a2cdef5555544444"
781 "\020a3cdef5555544444"
782 "\020a4cdef5555544444"
783 "\020a5cdef5555544444"
784 "\020a6cdef5555544444"
785 "\020a7cdef5555544444"
786 "\020a8cdef5555544444"
787 "\020a9cdef5555544444"
788 "\020aAcdef5555544444"
789 "\020aBcdef5555544444"
790 "\020aCcdef5555544444"
791 "\020aDcdef5555544444"
792 "\020aEcdef5555544444" /* 238 up to here */
793 "\007aabbccd" /* 246 up to here */
794 "\007example\000" /* 255 to here */
795 , 255) == 255);
796 unit_assert( dname_valid( (uint8_t*)
797 "\020a1cdef5555544444"
798 "\020a2cdef5555544444"
799 "\020a3cdef5555544444"
800 "\020a4cdef5555544444"
801 "\020a5cdef5555544444"
802 "\020a6cdef5555544444"
803 "\020a7cdef5555544444"
804 "\020a8cdef5555544444"
805 "\020a9cdef5555544444"
806 "\020aAcdef5555544444"
807 "\020aBcdef5555544444"
808 "\020aCcdef5555544444"
809 "\020aDcdef5555544444"
810 "\020aEcdef5555544444" /* 238 up to here */
811 "\007aabbccd" /* 246 up to here */
812 "\010exampleX\000" /* 256 to here */
813 , 4096) == 0);
814 }
815
816 /** Test dname_has_label */
817 static void
dname_test_has_label(void)818 dname_test_has_label(void)
819 {
820 unit_show_func("util/data/dname.c", "dname_has_label");
821 /* label past root label */
822 unit_assert(dname_has_label((uint8_t*)"\01a\0\01c", 5, (uint8_t*)"\01c") == 0);
823 /* label not found */
824 unit_assert(dname_has_label((uint8_t*)"\02ab\01c\0", 6, (uint8_t*)"\01e") == 0);
825 /* buffer too short */
826 unit_assert(dname_has_label((uint8_t*)"\02ab\01c\0", 5, (uint8_t*)"\0") == 0);
827 unit_assert(dname_has_label((uint8_t*)"\1a\0", 2, (uint8_t*)"\0") == 0);
828 unit_assert(dname_has_label((uint8_t*)"\0", 0, (uint8_t*)"\0") == 0);
829 unit_assert(dname_has_label((uint8_t*)"\02ab\01c", 4, (uint8_t*)"\01c") == 0);
830 unit_assert(dname_has_label((uint8_t*)"\02ab\03qwe\06oqieur\03def\01c\0", 19, (uint8_t*)"\01c") == 0);
831
832 /* positive cases */
833 unit_assert(dname_has_label((uint8_t*)"\0", 1, (uint8_t*)"\0") == 1);
834 unit_assert(dname_has_label((uint8_t*)"\1a\0", 3, (uint8_t*)"\0") == 1);
835 unit_assert(dname_has_label((uint8_t*)"\01a\0\01c", 5, (uint8_t*)"\0") == 1);
836 unit_assert(dname_has_label((uint8_t*)"\02ab\01c", 5, (uint8_t*)"\01c") == 1);
837 unit_assert(dname_has_label((uint8_t*)"\02ab\01c\0", 10, (uint8_t*)"\0") == 1);
838 unit_assert(dname_has_label((uint8_t*)"\02ab\01c\0", 7, (uint8_t*)"\0") == 1);
839 unit_assert(dname_has_label((uint8_t*)"\02ab\03qwe\06oqieur\03def\01c\0", 22, (uint8_t*)"\03def") == 1);
840 unit_assert(dname_has_label((uint8_t*)"\02ab\03qwe\06oqieur\03def\01c\0", 22, (uint8_t*)"\02ab") == 1);
841 unit_assert(dname_has_label((uint8_t*)"\02ab\03qwe\06oqieur\03def\01c\0", 22, (uint8_t*)"\01c") == 1);
842 }
843
844 /** test pkt_dname_tolower */
845 static void
dname_test_pdtl(sldns_buffer * loopbuf,sldns_buffer * boundbuf)846 dname_test_pdtl(sldns_buffer* loopbuf, sldns_buffer* boundbuf)
847 {
848 unit_show_func("util/data/dname.c", "pkt_dname_tolower");
849 pkt_dname_tolower(loopbuf, sldns_buffer_at(loopbuf, 12));
850 pkt_dname_tolower(boundbuf, sldns_buffer_at(boundbuf, 12));
851 }
852
853 /** setup looped dname and out-of-bounds dname ptr */
854 static void
dname_setup_bufs(sldns_buffer * loopbuf,sldns_buffer * boundbuf)855 dname_setup_bufs(sldns_buffer* loopbuf, sldns_buffer* boundbuf)
856 {
857 sldns_buffer_write_u16(loopbuf, 0xd54d); /* id */
858 sldns_buffer_write_u16(loopbuf, 0x12); /* flags */
859 sldns_buffer_write_u16(loopbuf, 1); /* qdcount */
860 sldns_buffer_write_u16(loopbuf, 0); /* ancount */
861 sldns_buffer_write_u16(loopbuf, 0); /* nscount */
862 sldns_buffer_write_u16(loopbuf, 0); /* arcount */
863 sldns_buffer_write_u8(loopbuf, 0xc0); /* PTR back at itself */
864 sldns_buffer_write_u8(loopbuf, 0x0c);
865 sldns_buffer_flip(loopbuf);
866
867 sldns_buffer_write_u16(boundbuf, 0xd54d); /* id */
868 sldns_buffer_write_u16(boundbuf, 0x12); /* flags */
869 sldns_buffer_write_u16(boundbuf, 1); /* qdcount */
870 sldns_buffer_write_u16(boundbuf, 0); /* ancount */
871 sldns_buffer_write_u16(boundbuf, 0); /* nscount */
872 sldns_buffer_write_u16(boundbuf, 0); /* arcount */
873 sldns_buffer_write_u8(boundbuf, 0x01); /* len=1 */
874 sldns_buffer_write_u8(boundbuf, (uint8_t)'A'); /* A. label */
875 sldns_buffer_write_u8(boundbuf, 0xc0); /* PTR out of bounds */
876 sldns_buffer_write_u8(boundbuf, 0xcc);
877 sldns_buffer_flip(boundbuf);
878 }
879
880 /* Test strings for the test_long_names test. */
881 /* Each label begins with the length of the label including the length octet. */
882
883 char desc_1[] = "Domain is 1 octet too long.";
884
885 uint8_t wire_dom_1[] = { /* Bad: Domain: (8x)0031abcdefghijklmnopqrstuvwxyz.0007ab. */
886 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
887 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
888 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
889 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
890 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
891 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
892 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
893 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
894 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
895 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
896 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
897 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61,
898 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
899 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62,
900 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72,
901 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, /* Bad: */ 0x06, 0x30, 0x30, 0x30, 0x37, 0x61, 0x62, 0x00
902 };
903
904 char desc_2[] = "Domain has the maximum allowed length (255).";
905
906 uint8_t wire_dom_2[] = { /* Good: Domain: (8x)0031abcdefghijklmnopqrstuvwxyz.00076a. */
907 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
908 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
909 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
910 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
911 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
912 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
913 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
914 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
915 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
916 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
917 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
918 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61,
919 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
920 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62,
921 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72,
922 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, /* Good: */ 0x05, 0x30, 0x30, 0x30, 0x36, 0x61, 0x00
923 };
924
925 char desc_3[] = "Domain has a length one label in the 255th position for a total of 257.";
926
927 uint8_t wire_dom_3[] = { /* Bad: Domain: (8x(0031abcdefghijklmnopqrstuvwxyz.0006ab.1. */
928 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
929 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
930 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
931 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
932 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
933 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
934 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
935 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
936 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
937 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
938 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
939 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61,
940 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
941 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62,
942 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72,
943 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, /* Bad: */ 0x05, 0x30, 0x30, 0x30, 0x36, 0x61, 0x01, 0x32, 0x00
944 };
945
946 char desc_4[] = "Domain has the maximum allowed length (255).";
947
948 uint8_t wire_dom_4[] = { /* Good: Domain: (8x)0031abcdefghijklmnopqrstuvwxyz.03.03. */
949 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
950 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
951 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
952 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
953 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
954 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
955 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
956 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
957 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
958 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
959 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
960 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61,
961 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
962 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62,
963 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72,
964 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, /* Good: */ 0x02, 0x30, 0x33, 0x02, 0x30, 0x33, 0x00
965 };
966
967 char desc_5[] = "Domain has a maximum length label (63) in the 255th position.";
968
969 uint8_t wire_dom_5[] = { /* Bad: Domain: (8x)0031abcdefghijklmnopqrstuvwxyz.03.03.65abc...zab...zab...ghi. */
970 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
971 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
972 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
973 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
974 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
975 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
976 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
977 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
978 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
979 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
980 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
981 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61,
982 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
983 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62,
984 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72,
985 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, /* Bad: */ 0x02, 0x30, 0x33, 0x02, 0x30, 0x33, 0x3f, 0x36,
986 0x33, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
987 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63, 0x64, 0x65,
988 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
989 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x00
990 };
991
992 char desc_6[] = "Domain has a too long label (65) in the 255th position.";
993
994 uint8_t wire_dom_6[] = { /* Bad: Domain: (8x)0031abcdefghijklmnopqrstuvwxyz.03.03.66abc...zab...zab...ijk. */
995 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
996 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
997 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
998 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
999 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
1000 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
1001 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
1002 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
1003 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
1004 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
1005 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
1006 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61,
1007 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
1008 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62,
1009 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72,
1010 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, /* Bad: */ 0x02, 0x30, 0x33, 0x02, 0x30, 0x33, 0x41, 0x36,
1011 0x36, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
1012 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63, 0x64, 0x65,
1013 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
1014 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
1015 0x00
1016 };
1017
1018 char desc_7[] = "Domain has a too long label (65) in the 187th position.";
1019
1020 uint8_t wire_dom_7[] = { /* Bad: Domain: (6x)0031abcdefghijklmnopqrstuvwxyz.65abc..zab...zab...ijk. */
1021 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
1022 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
1023 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
1024 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
1025 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
1026 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
1027 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
1028 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
1029 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
1030 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
1031 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
1032 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
1033 /* Bad: */ 0x41, 0x36,
1034 0x36, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
1035 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63, 0x64, 0x65,
1036 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
1037 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
1038 0x00
1039 };
1040
1041 char desc_8[] = "Domains has the maximum allowed length and ends with a maximum length label.";
1042
1043 uint8_t wire_dom_8[] = { /* Good: Domain: (6x)0031abcdefghijklmnopqrstuvwxyz.0004.0064abc..zab...zabcdefg. */
1044 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
1045 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
1046 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
1047 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
1048 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
1049 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
1050 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
1051 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
1052 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
1053 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
1054 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
1055 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x03, 0x30, 0x30, 0x34 ,/* Good: */ 0x3f, 0x30,
1056 0x30, 0x36, 0x34, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
1057 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63,
1058 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
1059 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x00
1060 };
1061
1062 char desc_9[] = "Domains has 254 octets, one less than the maximum allowed length.";
1063
1064 uint8_t wire_dom_9[] = { /* Good: Domain: (6x)0031abcdefghijklmnopqrstuvwxyz.0004.0064abc..zab...zabcdef. */
1065 0x1e, 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
1066 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e,
1067 0x30, 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
1068 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30,
1069 0x30, 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
1070 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30,
1071 0x33, 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
1072 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33,
1073 0x31, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
1074 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x1e, 0x30, 0x30, 0x33, 0x31,
1075 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
1076 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x03, 0x30, 0x30, 0x34 ,/* Good: */ 0x3e, 0x30,
1077 0x30, 0x35, 0x34, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
1078 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63,
1079 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
1080 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00
1081 };
1082
1083 /** Test dname to string with long domain names. */
1084 static void
test_long_names(void)1085 test_long_names(void)
1086 {
1087 /* Set to 1 for verbose output, 0 turns it off. */
1088 int verbtest = 0;
1089
1090 uint8_t* wire_doms[] = {wire_dom_1, wire_dom_2, wire_dom_3,
1091 wire_dom_4, wire_dom_5, wire_dom_6, wire_dom_7, wire_dom_8,
1092 wire_dom_9, 0};
1093 char* descs[] = {desc_1, desc_2, desc_3, desc_4, desc_5, desc_6,
1094 desc_7, desc_8, desc_9, 0};
1095
1096 int n;
1097 char string_domain[260];
1098 uint8_t** wd = wire_doms;
1099 int di = 0;
1100 int skip = 5; /* 0..6 */
1101
1102 while (*wd) {
1103
1104 if(verbtest)
1105 printf("Test: %s\n", descs[di++]);
1106
1107 memset(string_domain, 0xff, sizeof(string_domain));
1108 dname_str(*wd, string_domain);
1109 for (n = 0 ; n < (int)sizeof(string_domain); ++n) {
1110 if ((uint8_t)string_domain[n] == 0xff)
1111 break;
1112 }
1113 if(verbtest)
1114 printf("dname_str: L=%d, S=Skipping %d labels...%s\n",
1115 n, skip, string_domain + skip*31);
1116 unit_assert(n <= 255);
1117
1118 memset(string_domain, 0xff, sizeof(string_domain));
1119 sldns_wire2str_dname_buf(*wd,
1120 strlen((char*)*wd)+1 /* strlen works with these test strings */,
1121 string_domain,
1122 255 /* for comparable result to dname_str */ );
1123 for (n = 0 ; n < (int)sizeof(string_domain); ++n) {
1124 if ((uint8_t)string_domain[n] == 0xff)
1125 break;
1126 }
1127 if(verbtest)
1128 printf("sldns_wire2str_dname_buf: L=%d, S=Skipping %d labels...%s\n",
1129 n, skip, string_domain + skip*31);
1130 unit_assert(n <= 255);
1131
1132 ++wd;
1133 }
1134 }
1135
1136 static void
dname_test_str(sldns_buffer * buff)1137 dname_test_str(sldns_buffer* buff)
1138 {
1139 char result[LDNS_MAX_DOMAINLEN], expect[LDNS_MAX_DOMAINLEN], *e;
1140 size_t i;
1141 unit_show_func("util/data/dname.c", "dname_str");
1142
1143 /* root ; expected OK */
1144 sldns_buffer_clear(buff);
1145 sldns_buffer_write(buff, "\000", 1);
1146 sldns_buffer_flip(buff);
1147 unit_assert( sldns_buffer_limit(buff) == 1 );
1148 unit_assert( pkt_dname_len(buff) == 1 );
1149 dname_str(sldns_buffer_begin(buff), result);
1150 unit_assert( strcmp( ".", result) == 0 );
1151
1152 /* LDNS_MAX_DOMAINLEN - 1 ; expected OK */
1153 sldns_buffer_clear(buff);
1154 sldns_buffer_write(buff,
1155 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 64 up to here */
1156 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 128 up to here */
1157 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 192 up to here */
1158 "\074abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567" /* 253 up to here */
1159 "\000" /* 254 up to here */
1160 , 254);
1161 sldns_buffer_flip(buff);
1162 unit_assert( sldns_buffer_limit(buff) == 254 );
1163 unit_assert( pkt_dname_len(buff) == 254 );
1164 dname_str(sldns_buffer_begin(buff), result);
1165 unit_assert( strcmp(
1166 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1167 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1168 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1169 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567"
1170 ".", result) == 0 );
1171
1172 /* LDNS_MAX_DOMAINLEN ; expected OK */
1173 sldns_buffer_clear(buff);
1174 sldns_buffer_write(buff,
1175 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 64 up to here */
1176 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 128 up to here */
1177 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 192 up to here */
1178 "\075abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678" /* 254 up to here */
1179 "\000" /* 255 up to here */
1180 , 255);
1181 sldns_buffer_flip(buff);
1182 unit_assert( sldns_buffer_limit(buff) == 255 );
1183 unit_assert( pkt_dname_len(buff) == 255 );
1184 dname_str(sldns_buffer_begin(buff), result);
1185 unit_assert( strcmp(
1186 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1187 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1188 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1189 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678"
1190 ".", result) == 0 );
1191
1192 /* LDNS_MAX_DOMAINLEN + 1 ; expected to fail, output uses '&' on the latest label */
1193 sldns_buffer_clear(buff);
1194 sldns_buffer_write(buff,
1195 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 64 up to here */
1196 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 128 up to here */
1197 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 192 up to here */
1198 "\076abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" /* 255 up to here */
1199 "\000" /* 256 up to here */
1200 , 256);
1201 sldns_buffer_flip(buff);
1202 unit_assert( sldns_buffer_limit(buff) == 256 );
1203 unit_assert( pkt_dname_len(buff) == 0 );
1204 dname_str(sldns_buffer_begin(buff), result);
1205 unit_assert( strcmp(
1206 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1207 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1208 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1209 "&", result) == 0 );
1210
1211 /* LDNS_MAX_LABELLEN + 1 ; expected to fail, output uses '#' on the offending label */
1212 sldns_buffer_clear(buff);
1213 sldns_buffer_write(buff,
1214 "\077abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" /* 64 up to here */
1215 "\100abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890a" /* 129 up to here */
1216 "\000" /* 130 up to here */
1217 , 130);
1218 sldns_buffer_flip(buff);
1219 unit_assert( sldns_buffer_limit(buff) == 130 );
1220 unit_assert( pkt_dname_len(buff) == 0 );
1221 dname_str(sldns_buffer_begin(buff), result);
1222 unit_assert( strcmp(
1223 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890."
1224 "#", result) == 0 );
1225
1226 /* LDNS_MAX_DOMAINLEN with single labels; expected OK */
1227 sldns_buffer_clear(buff);
1228 for(i=0; i<=252; i+=2)
1229 sldns_buffer_write(buff, "\001a", 2);
1230 sldns_buffer_write_u8(buff, 0);
1231 sldns_buffer_flip(buff);
1232 unit_assert( sldns_buffer_limit(buff) == 255 );
1233 unit_assert( pkt_dname_len(buff) == 255 );
1234 dname_str(sldns_buffer_begin(buff), result);
1235 e = expect;
1236 for(i=0; i<=252; i+=2) {
1237 *e++ = 'a';
1238 *e++ = '.';
1239 }
1240 *e = '\0';
1241 unit_assert( strcmp(expect, result) == 0 );
1242
1243 /* LDNS_MAX_DOMAINLEN + 1 with single labels; expected to fail, output uses '&' on the latest label */
1244 sldns_buffer_clear(buff);
1245 for(i=0; i<=250; i+=2)
1246 sldns_buffer_write(buff, "\001a", 2);
1247 sldns_buffer_write(buff, "\002ab", 3);
1248 sldns_buffer_write_u8(buff, 0);
1249 sldns_buffer_flip(buff);
1250 unit_assert( sldns_buffer_limit(buff) == 256 );
1251 unit_assert( pkt_dname_len(buff) == 0 );
1252 dname_str(sldns_buffer_begin(buff), result);
1253 e = expect;
1254 for(i=0; i<=250; i+=2) {
1255 *e++ = 'a';
1256 *e++ = '.';
1257 }
1258 *e++ = '&';
1259 *e = '\0';
1260 unit_assert( strcmp(expect, result) == 0 );
1261
1262 /* Only alphas, numericals and '-', '_' and '*' are allowed in the output */
1263 for(i=1; i<=255; i++) {
1264 if(isalnum(i) || i == '-' || i == '_' || i == '*')
1265 continue;
1266 sldns_buffer_clear(buff);
1267 sldns_buffer_write_u8(buff, 1);
1268 sldns_buffer_write_u8(buff, (uint8_t)i);
1269 sldns_buffer_write_u8(buff, 0);
1270 sldns_buffer_flip(buff);
1271 unit_assert( sldns_buffer_limit(buff) == 3 );
1272 unit_assert( pkt_dname_len(buff) == 3);
1273 dname_str(sldns_buffer_begin(buff), result);
1274 if(strcmp( "?.", result) != 0 ) {
1275 log_err("ASCII value '0x%lX' allowed in string output", (unsigned long)i);
1276 unit_assert(0);
1277 }
1278 }
1279
1280 test_long_names();
1281 }
1282
dname_test(void)1283 void dname_test(void)
1284 {
1285 sldns_buffer* loopbuf = sldns_buffer_new(14);
1286 sldns_buffer* boundbuf = sldns_buffer_new(16);
1287 sldns_buffer* buff = sldns_buffer_new(65800);
1288 unit_assert(loopbuf && boundbuf && buff);
1289 sldns_buffer_flip(buff);
1290 dname_setup_bufs(loopbuf, boundbuf);
1291 dname_test_qdl(buff);
1292 dname_test_qdtl(buff);
1293 dname_test_pdtl(loopbuf, boundbuf);
1294 dname_test_query_dname_compare();
1295 dname_test_count_labels();
1296 dname_test_count_size_labels();
1297 dname_test_dname_lab_cmp();
1298 dname_test_pkt_dname_len(buff);
1299 dname_test_strict_subdomain();
1300 dname_test_subdomain();
1301 dname_test_isroot();
1302 dname_test_removelabel();
1303 dname_test_removelabellimitlen();
1304 dname_test_sigcount();
1305 dname_test_iswild();
1306 dname_test_canoncmp();
1307 dname_test_topdomain();
1308 dname_test_valid();
1309 dname_test_has_label();
1310 dname_test_str(buff);
1311 sldns_buffer_free(buff);
1312 sldns_buffer_free(loopbuf);
1313 sldns_buffer_free(boundbuf);
1314 }
1315