diff --git a/fuzz/.gitignore b/fuzz/.gitignore index 8a24d62c2a..78c8720ac4 100644 --- a/fuzz/.gitignore +++ b/fuzz/.gitignore @@ -1,5 +1,6 @@ /*.dSYM/ /*.out/ +/dns_master_load /dns_message_parse /dns_name_fromtext_target /dns_rdata_fromwire_text diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am index 2dae4543f5..1088f2d7d7 100644 --- a/fuzz/Makefile.am +++ b/fuzz/Makefile.am @@ -19,6 +19,7 @@ libfuzzmain_la_SOURCES = \ main.c check_PROGRAMS = \ + dns_master_load \ dns_message_parse \ dns_name_fromtext_target \ dns_rdata_fromwire_text \ @@ -26,6 +27,7 @@ check_PROGRAMS = \ isc_lex_gettoken EXTRA_DIST = \ + dns_master_load.in \ dns_message_parse.in \ dns_name_fromtext_target.in \ dns_rdata_fromwire_text.in \ diff --git a/fuzz/dns_master_load.c b/fuzz/dns_master_load.c new file mode 100644 index 0000000000..016cc880e5 --- /dev/null +++ b/fuzz/dns_master_load.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include "fuzz.h" + +bool debug = false; + +int +LLVMFuzzerInitialize(int *argc, char ***argv) { + UNUSED(argc); + UNUSED(argv); + return (0); +} + +int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + isc_buffer_t buf; + isc_result_t result; + isc_mem_t *mctx = NULL; + + isc_buffer_constinit(&buf, data, size); + isc_buffer_add(&buf, size); + isc_buffer_setactive(&buf, size); + + dns_rdatacallbacks_t callbacks; + dns_rdatacallbacks_init(&callbacks); + dns_db_t *db = NULL; + + isc_mem_create(&mctx); + result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, + dns_rdataclass_in, 0, NULL, &db); + if (result != ISC_R_SUCCESS) { + return 0; + } + + result = dns_db_beginload(db, &callbacks); + if (result != ISC_R_SUCCESS) { + goto end; + } + + result = dns_master_loadbuffer(&buf, &db->origin, &db->origin, + db->rdclass, DNS_MASTER_ZONE, &callbacks, + db->mctx); + if (debug) { + fprintf(stderr, "loadbuffer: %s\n", isc_result_totext(result)); + } + result = dns_db_endload(db, &callbacks); + if (debug) { + fprintf(stderr, "endload: %s\n", isc_result_totext(result)); + } + +end: + dns_db_detach(&db); + isc_mem_destroy(&mctx); + return (0); +} diff --git a/fuzz/dns_master_load.in/date.db b/fuzz/dns_master_load.in/date.db new file mode 100644 index 0000000000..62dd4566ac --- /dev/null +++ b/fuzz/dns_master_load.in/date.db @@ -0,0 +1,21 @@ +$TTL 300 ; 5 minutes +@ SOA mname1. . ( + 2000062101 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) + NS a1 +$DATE 20210101000000 + +a1 123 A \# 4 0A000001 +a2 456 A \# 4 0A000001 + +txt1 TXT \# 6 0568656C6C6F +txt2 TXT "hello" +txt3 TXT \# 6 0568656C6C6F +txt4 TXT "hello" + +unk1 TYPE123 \# 1 00 +unk2 TYPE123 \# 1 00 diff --git a/fuzz/dns_master_load.in/generate.db b/fuzz/dns_master_load.in/generate.db new file mode 100644 index 0000000000..8c2053dfbc --- /dev/null +++ b/fuzz/dns_master_load.in/generate.db @@ -0,0 +1,10 @@ +$ORIGIN . +$TTL 120 +@ SOA tld4. hostmaster.ns.tld4. ( 1 3600 1200 604800 60 ) + NS ns +ns A 10.53.0.2 +$GENERATE 11-18 all$.a9 A 192.0.2.8 +$GENERATE 1-2 @ PTR SERVER$.EXAMPLE. +$GENERATE 1-7 $ CNAME $.0 +$GENERATE 17-27 HOST-$ A 1.2.3.$ +$GENERATE 277-288 HOST-$ MX "0 ." diff --git a/fuzz/dns_master_load.in/include.db b/fuzz/dns_master_load.in/include.db new file mode 100644 index 0000000000..b83d7546f9 --- /dev/null +++ b/fuzz/dns_master_load.in/include.db @@ -0,0 +1,8 @@ +$ORIGIN . +$TTL 120 +@ SOA tld4. hostmaster.ns.tld4. ( 1 3600 1200 604800 60 ) + NS ns +ns A 10.53.0.2 +$INCLUDE withoutorigin +$INCLUDE withoutorigin origin + diff --git a/fuzz/dns_master_load.in/minimal.db b/fuzz/dns_master_load.in/minimal.db new file mode 100644 index 0000000000..54177a6845 --- /dev/null +++ b/fuzz/dns_master_load.in/minimal.db @@ -0,0 +1,4 @@ +. SOA ns1. hostmaster.warn.example. ( + 1 3600 1200 604800 3600 ) + NS ns1. +ns1. 555 IN A 10.53.0.1