Coverage Report

Created: 2026-12-01 07:04

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