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