diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:49:52 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:49:52 +0000 |
commit | 55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch) | |
tree | 33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/resolve/fuzz-resource-record.c | |
parent | Initial commit. (diff) | |
download | systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip |
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/resolve/fuzz-resource-record.c')
-rw-r--r-- | src/resolve/fuzz-resource-record.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/resolve/fuzz-resource-record.c b/src/resolve/fuzz-resource-record.c new file mode 100644 index 0000000..358a5c7 --- /dev/null +++ b/src/resolve/fuzz-resource-record.c @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "fd-util.h" +#include "fuzz.h" +#include "memory-util.h" +#include "memstream-util.h" +#include "resolved-dns-packet.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL, *copy = NULL; + _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(memstream_done) MemStream m = {}; + FILE *f; + + if (outside_size_range(size, 0, DNS_PACKET_SIZE_MAX)) + return 0; + + if (dns_resource_record_new_from_raw(&rr, data, size) < 0) + return 0; + + fuzz_setup_logging(); + + assert_se(copy = dns_resource_record_copy(rr)); + assert_se(dns_resource_record_equal(copy, rr) > 0); + + assert_se(f = memstream_init(&m)); + (void) fprintf(f, "%s", strna(dns_resource_record_to_string(rr))); + + if (dns_resource_record_to_json(rr, &v) < 0) + return 0; + + (void) json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR|JSON_FORMAT_SOURCE, f, NULL); + (void) dns_resource_record_to_wire_format(rr, false); + (void) dns_resource_record_to_wire_format(rr, true); + + return 0; +} |