2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Add dns_master_loadbuffer() fuzzer

Corpus focuses on "extra" things in master files like $GENERATE etc.
Text encoding for RRs is thoroughly tested in dns_rdata_fromtext
fuzzer.
This commit is contained in:
Petr Špaček
2021-02-19 18:08:36 +01:00
parent 40caf57cf5
commit 5076355822
7 changed files with 124 additions and 0 deletions

1
fuzz/.gitignore vendored
View File

@@ -1,5 +1,6 @@
/*.dSYM/
/*.out/
/dns_master_load
/dns_message_parse
/dns_name_fromtext_target
/dns_rdata_fromwire_text

View File

@@ -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 \

78
fuzz/dns_master_load.c Normal file
View File

@@ -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 <stdbool.h>
#include <stdlib.h>
#include <isc/buffer.h>
#include <isc/mem.h>
#include <isc/util.h>
#include <dns/callbacks.h>
#include <dns/db.h>
#include <dns/master.h>
#include <dns/types.h>
#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);
}

View File

@@ -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

View File

@@ -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 ."

View File

@@ -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

View File

@@ -0,0 +1,4 @@
. SOA ns1. hostmaster.warn.example. (
1 3600 1200 604800 3600 )
NS ns1.
ns1. 555 IN A 10.53.0.1