Coverage Report

Created: 2026-03-31 06:10

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