Coverage Report

Created: 2026-06-30 07:04

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