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