Coverage Report

Created: 2025-11-11 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/unbound/fuzz_1.c
Line
Count
Source
1
/* Copyright 2021 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
13
/*
14
 * unbound-fuzzme.c - parse a packet provided on stdin (for fuzzing).
15
 *
16
 */
17
#include "config.h"
18
#include "util/regional.h"
19
#include "util/module.h"
20
#include "util/config_file.h"
21
#include "iterator/iterator.h"
22
#include "iterator/iter_priv.h"
23
#include "iterator/iter_scrub.h"
24
#include "util/log.h"
25
#include "sldns/sbuffer.h"
26
27
7.88k
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
28
7.88k
  log_init("/tmp/foo", 0, NULL);
29
7.88k
  char *bin = buf;
30
7.88k
  struct regional* reg;
31
32
7.88k
  struct sldns_buffer *pkt = sldns_buffer_new(1);
33
7.88k
  sldns_buffer_new_frm_data(pkt, bin, len);
34
35
7.88k
  reg = regional_create();
36
37
7.88k
  struct msg_parse msg;
38
7.88k
  struct edns_data edns;
39
7.88k
  memset(&msg, 0, sizeof(struct msg_parse));
40
7.88k
  memset(&edns, 0, sizeof(edns));
41
7.88k
  if (parse_packet(pkt, &msg, reg) != LDNS_RCODE_NOERROR) {    
42
4.66k
    goto out;
43
4.66k
  }
44
3.22k
  if (parse_extract_edns_from_response_msg(&msg, &edns, reg) != LDNS_RCODE_NOERROR) {
45
6
    goto out;
46
6
  }
47
48
49
3.21k
  struct query_info qinfo_out;
50
3.21k
  memset(&qinfo_out, 0, sizeof(struct query_info));
51
3.21k
  qinfo_out.qname = (unsigned char *) "\03nic\02de";
52
3.21k
  uint8_t *peter = (unsigned char *) "\02de";   // zonename  
53
3.21k
  struct module_env env;
54
3.21k
  memset(&env, 0, sizeof(struct module_env));
55
3.21k
  struct config_file cfg;
56
3.21k
  memset(&cfg, 0, sizeof(struct config_file));
57
3.21k
  cfg.harden_glue = 1;    // crashes now, want to remove that later
58
3.21k
  env.cfg = &cfg;
59
60
3.21k
  struct iter_env ie;
61
3.21k
  memset(&ie, 0, sizeof(struct iter_env));
62
63
3.21k
  struct iter_priv priv;
64
3.21k
  memset(&priv, 0, sizeof(struct iter_priv));
65
3.21k
  ie.priv = &priv;
66
67
3.21k
  struct module_qstate qstate;
68
3.21k
  memset(&qstate, 0, sizeof(struct module_qstate));
69
3.21k
  qstate.env = &env;
70
3.21k
  qstate.region = reg;
71
72
3.21k
  scrub_message(pkt, &msg, &qinfo_out, peter, reg, &env, &qstate, &ie);
73
7.88k
out:
74
7.88k
  regional_destroy(reg);
75
7.88k
  sldns_buffer_free(pkt);
76
7.88k
  return 0;
77
3.21k
}