Coverage Report

Created: 2026-08-06 06:25

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