Debian Codegraph @

fuzz/dns_master_load.c

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