Coverage Report

Created: 2026-01-16 06:59

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