Coverage Report

Created: 2025-12-31 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz_mroute.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 "mroute.h"
17
18
#include "fuzz_randomizer.h"
19
20
21
388
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
22
23
388
  fuzz_random_init(data, size);
24
388
  struct buffer buf;
25
388
  struct gc_arena gc;
26
27
388
  gc = gc_new();
28
29
388
  char *tmp = get_random_string();
30
388
  buf = string_alloc_buf(tmp, &gc);
31
388
  free(tmp);
32
33
388
  struct mroute_addr src_addr;
34
388
  struct mroute_addr dst_addr;
35
388
  mroute_addr_init(&src_addr);
36
388
  mroute_addr_init(&dst_addr);
37
388
  unsigned int ret = mroute_extract_addr_ip(&src_addr, &dst_addr, &buf);
38
39
388
  if (ret & MROUTE_EXTRACT_SUCCEEDED) {
40
172
    mroute_addr_mask_host_bits(&src_addr);
41
172
    mroute_addr_print(&src_addr, &gc);
42
172
    mroute_learnable_address(&src_addr, &gc);
43
172
  }
44
45
388
  uint16_t vid;
46
388
  struct mroute_addr a1, a2;
47
388
  mroute_addr_init(&a1);
48
388
  mroute_addr_init(&a2);
49
388
  mroute_extract_addr_ether(&a1, &a2, vid, &buf);
50
51
388
  if (size > sizeof(struct openvpn_sockaddr)) {
52
289
    struct openvpn_sockaddr local_sock;
53
289
    memcpy(&local_sock, data, sizeof(struct openvpn_sockaddr));
54
289
    mroute_extract_openvpn_sockaddr(&a1, &local_sock, true);
55
289
    mroute_extract_openvpn_sockaddr(&a1, &local_sock, false);
56
289
  }
57
58
388
  struct mroute_helper *mhelper = NULL;
59
388
  mhelper = mroute_helper_init(fuzz_randomizer_get_int(0, 0xfffffff));
60
388
  if (mhelper != NULL) {
61
388
    mroute_helper_add_iroute46(mhelper, fuzz_randomizer_get_int(0, MR_HELPER_NET_LEN-1));
62
388
    mroute_helper_free(mhelper);
63
388
  }
64
65
388
  gc_free(&gc);
66
67
388
  fuzz_random_destroy();
68
388
  return 0;
69
388
}
70