Coverage Report

Created: 2026-02-14 06:40

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