1 /* $NetBSD: dns_master_load.c,v 1.3 2025/01/26 16:25:20 christos 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, ZONEDB_DEFAULT, dns_rootname, 55 dns_dbtype_zone, dns_rdataclass_in, 0, NULL, 56 &db); 57 if (result != ISC_R_SUCCESS) { 58 return 0; 59 } 60 61 result = dns_db_beginload(db, &callbacks); 62 if (result != ISC_R_SUCCESS) { 63 goto end; 64 } 65 66 result = dns_master_loadbuffer(&buf, &db->origin, &db->origin, 67 db->rdclass, DNS_MASTER_ZONE, &callbacks, 68 db->mctx); 69 if (debug) { 70 fprintf(stderr, "loadbuffer: %s\n", isc_result_totext(result)); 71 } 72 result = dns_db_endload(db, &callbacks); 73 if (debug) { 74 fprintf(stderr, "endload: %s\n", isc_result_totext(result)); 75 } 76 77 end: 78 dns_db_detach(&db); 79 isc_mem_destroy(&mctx); 80 return 0; 81 } 82