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 | | #include "config.h" |
14 | | #include "syshead.h" |
15 | | #include "init.h" |
16 | | #include "proxy.h" |
17 | | #include "interval.h" |
18 | | #include "route.h" |
19 | | #include "buffer.h" |
20 | | |
21 | | #include "fuzz_randomizer.h" |
22 | | |
23 | 484 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
24 | | |
25 | 484 | fuzz_random_init(data, size); |
26 | | |
27 | 484 | gb_init(); |
28 | | |
29 | 484 | struct route_option_list *opt; |
30 | 484 | struct route_list rl; |
31 | | |
32 | 484 | int route_list_inited = 0; |
33 | 484 | int route_list_ipv6_inited = 0; |
34 | | |
35 | 484 | struct context c; |
36 | 484 | memset(&c, 0, sizeof(struct context)); |
37 | 484 | gc_init(&c.gc); |
38 | 484 | c.es = env_set_create(&c.gc); |
39 | 484 | init_options(&c.options); |
40 | 484 | net_ctx_init(&c, &c.net_ctx); |
41 | 484 | init_verb_mute(&c, IVM_LEVEL_1); |
42 | | |
43 | 484 | init_options_dev(&c.options); |
44 | | |
45 | | // options_postprocess(&c.options); |
46 | 484 | pre_setup(&c.options); |
47 | | |
48 | 484 | setenv_settings(c.es, &c.options); |
49 | | |
50 | 484 | ALLOC_OBJ_CLEAR_GC(c.options.ce.local_list, struct local_list, &c.options.gc); |
51 | 484 | ALLOC_OBJ_CLEAR_GC(c.options.connection_list, struct connection_list, |
52 | 484 | &c.options.gc); |
53 | 484 | context_init_1(&c); |
54 | | |
55 | 484 | in_addr_t remote_host; |
56 | 484 | ssize_t default_metric; |
57 | | |
58 | 484 | struct route_ipv6_list rl6; |
59 | 484 | struct route_ipv6_option_list *opt6; |
60 | | |
61 | 484 | memset(&rl, 0, sizeof(rl)); |
62 | 484 | memset(&rl6, 0, sizeof(rl6)); |
63 | 484 | memset(&opt, 0, sizeof(opt)); |
64 | 484 | memset(&opt6, 0, sizeof(opt6)); |
65 | | |
66 | 484 | opt6 = new_route_ipv6_option_list(&c.gc); |
67 | 484 | opt = new_route_option_list(&c.gc); |
68 | | |
69 | 484 | int total_to_fuzz = fuzz_randomizer_get_int(1, 20); |
70 | 8.98k | for (int i = 0; i < total_to_fuzz; i++) { |
71 | 8.50k | int selector = fuzz_randomizer_get_int(0, 13); |
72 | 8.50k | switch (selector) { |
73 | 3.20k | case 0: |
74 | 3.20k | if (route_list_inited == 0) { |
75 | 929 | const char *remote_endpoint = gb_get_random_string(); |
76 | 929 | memset(&rl, 0, sizeof(struct route_list)); |
77 | 929 | rl.flags = fuzz_randomizer_get_int(0, 0xffffff); |
78 | | |
79 | 929 | init_route_list(&rl, opt, remote_endpoint, default_metric, remote_host, |
80 | 929 | c.es, &c); |
81 | 929 | route_list_inited = 1; |
82 | 929 | } |
83 | 3.20k | break; |
84 | 91 | case 1: |
85 | 91 | if (route_list_inited) { |
86 | 50 | in_addr_t addr; |
87 | 50 | route_list_add_vpn_gateway(&rl, c.es, addr); |
88 | 50 | } |
89 | 91 | break; |
90 | 248 | case 2: |
91 | 248 | if (route_list_inited && route_list_ipv6_inited) { |
92 | 140 | struct tuntap tt; |
93 | 140 | memset(&tt, 0, sizeof(tt)); |
94 | 140 | add_routes(&rl, &rl6, &tt, 0, c.es, &c); |
95 | 140 | } |
96 | 248 | break; |
97 | 266 | case 3: |
98 | 266 | if (route_list_inited) { |
99 | 160 | setenv_routes(c.es, &rl); |
100 | 160 | } |
101 | 266 | break; |
102 | 164 | case 4: |
103 | 164 | if (route_list_inited) { |
104 | 123 | struct route_ipv4 r; |
105 | 123 | struct route_option ro; |
106 | 123 | ro.network = gb_get_random_string(); |
107 | 123 | ro.netmask = gb_get_random_string(); |
108 | 123 | ro.gateway = gb_get_random_string(); |
109 | 123 | ro.metric = gb_get_random_string(); |
110 | 123 | ro.next = NULL; |
111 | | |
112 | 123 | memset(&r, 0, sizeof(struct route_ipv4)); |
113 | 123 | r.option = &ro; |
114 | 123 | r.flags = RT_DEFINED; |
115 | 123 | add_route(&r, NULL, 0, NULL, c.es, &c); |
116 | 123 | } |
117 | 164 | break; |
118 | 570 | case 5: |
119 | 570 | if (route_list_inited) { |
120 | 511 | char *s1 = get_random_string(); |
121 | 511 | is_special_addr(s1); |
122 | 511 | free(s1); |
123 | 511 | } |
124 | 570 | break; |
125 | 877 | case 6: |
126 | 877 | if (route_list_ipv6_inited == 0) { |
127 | 752 | const char *remote_endpoint = gb_get_random_string(); |
128 | 752 | memset(&rl, 0, sizeof(struct route_list)); |
129 | 752 | struct in6_addr remote_host; |
130 | | |
131 | 752 | rl6.rgi6.flags = fuzz_randomizer_get_int(0, 0xffffff); |
132 | 752 | fuzz_get_random_data(&rl6.rgi6.hwaddr, 6); |
133 | | |
134 | 752 | char *t1 = gb_get_random_string(); |
135 | 752 | if (strlen(t1) > 16) { |
136 | 83 | memcpy(rl6.rgi6.iface, t1, 16); |
137 | 669 | } else { |
138 | 669 | memcpy(rl6.rgi6.iface, t1, strlen(t1)); |
139 | 669 | } |
140 | | |
141 | 752 | init_route_ipv6_list(&rl6, opt6, remote_endpoint, 0, &remote_host, c.es, |
142 | 752 | &c); |
143 | 752 | route_list_ipv6_inited = 1; |
144 | 752 | } |
145 | 877 | break; |
146 | 222 | case 7: { |
147 | 222 | unsigned int flags; |
148 | 222 | struct route_ipv6 r6; |
149 | 222 | struct tuntap tt; |
150 | 222 | memset(&tt, 0, sizeof(tt)); |
151 | 222 | tt.actual_name = gb_get_random_string(); |
152 | 222 | r6.iface = gb_get_random_string(); |
153 | 222 | r6.flags = fuzz_randomizer_get_int(0, 0xfffff); |
154 | 222 | r6.netbits = fuzz_randomizer_get_int(0, 0xfffff); |
155 | 222 | r6.metric = fuzz_randomizer_get_int(0, 0xfffff); |
156 | | |
157 | 222 | r6.next = NULL; |
158 | | |
159 | 222 | add_route_ipv6(&r6, &tt, 0, c.es, &c); |
160 | 222 | } break; |
161 | 751 | case 8: |
162 | 751 | if (route_list_ipv6_inited && route_list_inited) { |
163 | 525 | delete_routes(&rl, &rl6, NULL, 0, c.es, &c); |
164 | 525 | route_list_ipv6_inited = 0; |
165 | 525 | route_list_inited = 0; |
166 | 525 | } |
167 | 751 | break; |
168 | 198 | case 9: |
169 | 198 | if (route_list_ipv6_inited) { |
170 | 106 | setenv_routes_ipv6(c.es, &rl6); |
171 | 106 | } |
172 | 198 | break; |
173 | 597 | case 10: { |
174 | 597 | add_route_ipv6_to_option_list(opt6, |
175 | 597 | gb_get_random_string(), |
176 | 597 | gb_get_random_string(), |
177 | 597 | gb_get_random_string(), |
178 | 597 | fuzz_randomizer_get_int(0, 100)); |
179 | 597 | } break; |
180 | 72 | case 11: { |
181 | 72 | print_route_options(opt, M_NONFATAL); |
182 | 72 | } break; |
183 | 1.12k | case 12: { |
184 | 1.12k | add_route_to_option_list(opt, |
185 | 1.12k | gb_get_random_string(), |
186 | 1.12k | gb_get_random_string(), |
187 | 1.12k | gb_get_random_string(), |
188 | 1.12k | gb_get_random_string(), |
189 | 1.12k | fuzz_randomizer_get_int(0, 100)); |
190 | 1.12k | } break; |
191 | 115 | default: |
192 | 115 | break; |
193 | 8.50k | } |
194 | 8.50k | } |
195 | | |
196 | 484 | if (route_list_inited) { |
197 | 404 | gc_free(&rl.gc); |
198 | 404 | } |
199 | 484 | env_set_destroy(c.es); |
200 | 484 | context_gc_free(&c); |
201 | | |
202 | 484 | fuzz_random_destroy(); |
203 | | |
204 | 484 | gb_cleanup(); |
205 | | |
206 | 484 | return 0; |
207 | 484 | } |