Home | History | Annotate | Line # | Download | only in fuzz
dns_master_load.c revision 1.2.4.2
      1 /*	$NetBSD: dns_master_load.c,v 1.2.4.2 2024/02/29 12:33:43 martin Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * SPDX-License-Identifier: MPL-2.0
      7  *
      8  * This Source Code Form is subject to the terms of the Mozilla Public
      9  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  *
     12  * See the COPYRIGHT file distributed with this work for additional
     13  * information regarding copyright ownership.
     14  */
     15 
     16 #include <stdbool.h>
     17 #include <stdlib.h>
     18 
     19 #include <isc/buffer.h>
     20 #include <isc/mem.h>
     21 #include <isc/util.h>
     22 
     23 #include <dns/callbacks.h>
     24 #include <dns/db.h>
     25 #include <dns/master.h>
     26 #include <dns/types.h>
     27 
     28 #include "fuzz.h"
     29 
     30 bool debug = false;
     31 
     32 int
     33 LLVMFuzzerInitialize(int *argc, char ***argv) {
     34 	UNUSED(argc);
     35 	UNUSED(argv);
     36 	return (0);
     37 }
     38 
     39 int
     40 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     41 	isc_buffer_t buf;
     42 	isc_result_t result;
     43 	isc_mem_t *mctx = NULL;
     44 
     45 	isc_buffer_constinit(&buf, data, size);
     46 	isc_buffer_add(&buf, size);
     47 	isc_buffer_setactive(&buf, size);
     48 
     49 	dns_rdatacallbacks_t callbacks;
     50 	dns_rdatacallbacks_init(&callbacks);
     51 	dns_db_t *db = NULL;
     52 
     53 	isc_mem_create(&mctx);
     54 	result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone,
     55 			       dns_rdataclass_in, 0, NULL, &db);
     56 	if (result != ISC_R_SUCCESS) {
     57 		return 0;
     58 	}
     59 
     60 	result = dns_db_beginload(db, &callbacks);
     61 	if (result != ISC_R_SUCCESS) {
     62 		goto end;
     63 	}
     64 
     65 	result = dns_master_loadbuffer(&buf, &db->origin, &db->origin,
     66 				       db->rdclass, DNS_MASTER_ZONE, &callbacks,
     67 				       db->mctx);
     68 	if (debug) {
     69 		fprintf(stderr, "loadbuffer: %s\n", isc_result_totext(result));
     70 	}
     71 	result = dns_db_endload(db, &callbacks);
     72 	if (debug) {
     73 		fprintf(stderr, "endload: %s\n", isc_result_totext(result));
     74 	}
     75 
     76 end:
     77 	dns_db_detach(&db);
     78 	isc_mem_destroy(&mctx);
     79 	return (0);
     80 }
     81