1:255.16-alt1
[systemd_ALT.git] / src / resolve / fuzz-resource-record.c
blob358a5c7594b887b9805724957541bc8996059987
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "fd-util.h"
4 #include "fuzz.h"
5 #include "memory-util.h"
6 #include "memstream-util.h"
7 #include "resolved-dns-packet.h"
9 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
10 _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL, *copy = NULL;
11 _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
12 _cleanup_(memstream_done) MemStream m = {};
13 FILE *f;
15 if (outside_size_range(size, 0, DNS_PACKET_SIZE_MAX))
16 return 0;
18 if (dns_resource_record_new_from_raw(&rr, data, size) < 0)
19 return 0;
21 fuzz_setup_logging();
23 assert_se(copy = dns_resource_record_copy(rr));
24 assert_se(dns_resource_record_equal(copy, rr) > 0);
26 assert_se(f = memstream_init(&m));
27 (void) fprintf(f, "%s", strna(dns_resource_record_to_string(rr)));
29 if (dns_resource_record_to_json(rr, &v) < 0)
30 return 0;
32 (void) json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR|JSON_FORMAT_SOURCE, f, NULL);
33 (void) dns_resource_record_to_wire_format(rr, false);
34 (void) dns_resource_record_to_wire_format(rr, true);
36 return 0;