Coverage Report

Created: 2026-05-16 06:27

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