1 /*
2  * unbound-fuzzme.c - parse a packet provided on stdin (for fuzzing).
3  *
4  */
5 #include "config.h"
6 #include "util/regional.h"
7 #include "util/module.h"
8 #include "util/config_file.h"
9 #include "iterator/iterator.h"
10 #include "iterator/iter_priv.h"
11 #include "iterator/iter_scrub.h"
12 #include "util/log.h"
13 #include "sldns/sbuffer.h"
14 
LLVMFuzzerTestOneInput(const uint8_t * buf,size_t len)15 int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
16   log_init("/tmp/foo", 0, NULL);
17   char *bin = buf;
18   struct regional* reg;
19 
20   struct sldns_buffer *pkt = sldns_buffer_new(1);
21   sldns_buffer_new_frm_data(pkt, bin, len);
22 
23   reg = regional_create();
24 
25   struct msg_parse msg;
26   struct edns_data edns;
27   memset(&msg, 0, sizeof(struct msg_parse));
28   memset(&edns, 0, sizeof(edns));
29   if (parse_packet(pkt, &msg, reg) != LDNS_RCODE_NOERROR) {
30     goto out;
31   }
32   if (parse_extract_edns(&msg, &edns, reg) != LDNS_RCODE_NOERROR) {
33     goto out;
34   }
35 
36 
37   struct query_info qinfo_out;
38   memset(&qinfo_out, 0, sizeof(struct query_info));
39   qinfo_out.qname = (unsigned char *) "\03nic\02de";
40   uint8_t *peter = (unsigned char *) "\02de";   // zonename
41   struct module_env env;
42   memset(&env, 0, sizeof(struct module_env));
43   struct config_file cfg;
44   memset(&cfg, 0, sizeof(struct config_file));
45   cfg.harden_glue = 1;    // crashes now, want to remove that later
46   env.cfg = &cfg;
47 
48   struct iter_env ie;
49   memset(&ie, 0, sizeof(struct iter_env));
50 
51   struct iter_priv priv;
52   memset(&priv, 0, sizeof(struct iter_priv));
53   ie.priv = &priv;
54   scrub_message(pkt, &msg, &qinfo_out, peter, reg, &env, &ie);
55 out:
56   regional_destroy(reg);
57   sldns_buffer_free(pkt);
58   return 0;
59 }
60