| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-json.h" |
| 4 |
|
| 5 |
#include "dns-packet.h" |
| 6 |
#include "dns-rr.h" |
| 7 |
#include "fuzz.h" |
| 8 |
#include "memstream-util.h" |
| 9 |
#include "string-util.h" |
| 10 |
|
| 11 |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 12 |
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL, *copy = NULL; |
| 13 |
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; |
| 14 |
_cleanup_(memstream_done) MemStream m = {}; |
| 15 |
FILE *f; |
| 16 |
|
| 17 |
if (outside_size_range(size, 0, DNS_PACKET_SIZE_MAX)) |
| 18 |
return 0; |
| 19 |
|
| 20 |
if (dns_resource_record_new_from_raw(&rr, data, size) < 0) |
| 21 |
return 0; |
| 22 |
|
| 23 |
fuzz_setup_logging(); |
| 24 |
|
| 25 |
assert_se(copy = dns_resource_record_copy(rr)); |
| 26 |
assert_se(dns_resource_record_equal(copy, rr) > 0); |
| 27 |
|
| 28 |
assert_se(f = memstream_init(&m)); |
| 29 |
(void) fprintf(f, "%s", strna(dns_resource_record_to_string(rr))); |
| 30 |
|
| 31 |
assert_se(dns_resource_record_to_json(rr, &v) >= 0); |
| 32 |
assert_se(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_COLOR|SD_JSON_FORMAT_SOURCE, f, NULL) >= 0); |
| 33 |
assert_se(dns_resource_record_to_wire_format(rr, false) >= 0); |
| 34 |
assert_se(dns_resource_record_to_wire_format(rr, true) >= 0); |
| 35 |
|
| 36 |
return 0; |
| 37 |
} |