Coverage Report

Created: 2026-03-07 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/fuzz/dns_master_load.c
Line
Count
Source
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
18
LLVMFuzzerInitialize(int *argc, char ***argv) {
32
18
  UNUSED(argc);
33
18
  UNUSED(argv);
34
18
  return 0;
35
18
}
36
37
int
38
18.1k
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
39
18.1k
  isc_buffer_t buf;
40
18.1k
  isc_result_t result;
41
18.1k
  isc_mem_t *mctx = NULL;
42
43
18.1k
  isc_buffer_constinit(&buf, data, size);
44
18.1k
  isc_buffer_add(&buf, size);
45
18.1k
  isc_buffer_setactive(&buf, size);
46
47
18.1k
  dns_rdatacallbacks_t callbacks;
48
18.1k
  dns_rdatacallbacks_init(&callbacks);
49
18.1k
  dns_db_t *db = NULL;
50
51
18.1k
  isc_mem_create("fuzz", &mctx);
52
18.1k
  result = dns_db_create(mctx, ZONEDB_DEFAULT, dns_rootname,
53
18.1k
             dns_dbtype_zone, dns_rdataclass_in, 0, NULL,
54
18.1k
             &db);
55
18.1k
  if (result != ISC_R_SUCCESS) {
56
0
    return 0;
57
0
  }
58
59
18.1k
  result = dns_db_beginload(db, &callbacks);
60
18.1k
  if (result != ISC_R_SUCCESS) {
61
0
    goto end;
62
0
  }
63
64
18.1k
  result = dns_master_loadbuffer(&buf, &db->origin, &db->origin,
65
18.1k
               db->rdclass, DNS_MASTER_ZONE, &callbacks,
66
18.1k
               db->mctx);
67
18.1k
  if (debug) {
68
0
    fprintf(stderr, "loadbuffer: %s\n", isc_result_totext(result));
69
0
  }
70
18.1k
  result = dns_db_endload(db, &callbacks);
71
18.1k
  if (debug) {
72
0
    fprintf(stderr, "endload: %s\n", isc_result_totext(result));
73
0
  }
74
75
18.1k
end:
76
18.1k
  dns_db_detach(&db);
77
18.1k
  isc_mem_detach(&mctx);
78
18.1k
  return 0;
79
18.1k
}