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 | 3.88k | int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { |
28 | 3.88k | log_init("/tmp/foo", 0, NULL); |
29 | 3.88k | char *bin = buf; |
30 | 3.88k | struct regional* reg; |
31 | | |
32 | 3.88k | struct sldns_buffer *pkt = sldns_buffer_new(1); |
33 | 3.88k | sldns_buffer_new_frm_data(pkt, bin, len); |
34 | | |
35 | 3.88k | reg = regional_create(); |
36 | | |
37 | 3.88k | struct msg_parse msg; |
38 | 3.88k | struct edns_data edns; |
39 | 3.88k | memset(&msg, 0, sizeof(struct msg_parse)); |
40 | 3.88k | memset(&edns, 0, sizeof(edns)); |
41 | 3.88k | if (parse_packet(pkt, &msg, reg) != LDNS_RCODE_NOERROR) { |
42 | 2.40k | goto out; |
43 | 2.40k | } |
44 | 1.48k | if (parse_extract_edns_from_response_msg(&msg, &edns, reg) != LDNS_RCODE_NOERROR) { |
45 | 3 | goto out; |
46 | 3 | } |
47 | | |
48 | | |
49 | 1.47k | struct query_info qinfo_out; |
50 | 1.47k | memset(&qinfo_out, 0, sizeof(struct query_info)); |
51 | 1.47k | qinfo_out.qname = (unsigned char *) "\03nic\02de"; |
52 | 1.47k | uint8_t *peter = (unsigned char *) "\02de"; // zonename |
53 | 1.47k | struct module_env env; |
54 | 1.47k | memset(&env, 0, sizeof(struct module_env)); |
55 | 1.47k | struct config_file cfg; |
56 | 1.47k | memset(&cfg, 0, sizeof(struct config_file)); |
57 | 1.47k | cfg.harden_glue = 1; // crashes now, want to remove that later |
58 | 1.47k | env.cfg = &cfg; |
59 | | |
60 | 1.47k | struct iter_env ie; |
61 | 1.47k | memset(&ie, 0, sizeof(struct iter_env)); |
62 | | |
63 | 1.47k | struct iter_priv priv; |
64 | 1.47k | memset(&priv, 0, sizeof(struct iter_priv)); |
65 | 1.47k | ie.priv = &priv; |
66 | | |
67 | 1.47k | struct module_qstate qstate; |
68 | 1.47k | memset(&qstate, 0, sizeof(struct module_qstate)); |
69 | 1.47k | qstate.env = &env; |
70 | 1.47k | qstate.region = reg; |
71 | | |
72 | 1.47k | scrub_message(pkt, &msg, &qinfo_out, peter, reg, &env, &qstate, &ie); |
73 | 3.88k | out: |
74 | 3.88k | regional_destroy(reg); |
75 | 3.88k | sldns_buffer_free(pkt); |
76 | 3.88k | return 0; |
77 | 1.47k | } |