Coverage Report

Created: 2026-03-31 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz_list.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 "list.h"
16
17
#include "fuzz_randomizer.h"
18
19
6.99k
#define KEY_SIZE 23
20
21
/* Required for hash_init() */
22
3.22k
static uint32_t word_hash_function(const void *key, uint32_t iv) {
23
3.22k
  return hash_func(key, KEY_SIZE, iv);
24
3.22k
}
25
26
/* Required for hash_init() */
27
302
static bool word_compare_function(const void *key1, const void *key2) {
28
302
  return ((size_t)key1 & 0xFFF) == ((size_t)key1 & 0xFFF);
29
302
}
30
31
528
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32
528
  struct gc_arena gc;
33
528
  struct hash *hash = NULL;
34
528
  ssize_t generic_ssizet, generic_ssizet2, num_loops;
35
36
528
  fuzz_random_init(data, size);
37
38
528
  gc = gc_new();
39
40
528
  int total_to_fuzz = fuzz_randomizer_get_int(1, 20);
41
9.31k
  for (int i = 0; i < total_to_fuzz; i++) {
42
8.79k
    generic_ssizet = fuzz_randomizer_get_int(0, 8);
43
44
8.79k
    switch (generic_ssizet) {
45
5.44k
    case 0:
46
5.44k
      if (hash == NULL) {
47
583
        int n_buckets = fuzz_randomizer_get_int(1, 1000);
48
583
        uint32_t iv;
49
50
583
        hash =
51
583
            hash_init(n_buckets, iv, word_hash_function, word_compare_function);
52
583
      }
53
5.44k
      break;
54
123
    case 1:
55
123
      if (hash) {
56
72
        hash_free(hash);
57
72
        hash = NULL;
58
72
      }
59
123
      break;
60
336
    case 2:
61
336
      if (hash) {
62
293
        struct hash_iterator hi;
63
293
        struct hash_element *he;
64
293
        hash_iterator_init(hash, &hi);
65
1.19k
        while ((he = hash_iterator_next(&hi))) {
66
904
          void *w = he->value;
67
904
        }
68
293
        hash_iterator_free(&hi);
69
293
      }
70
336
      break;
71
1.52k
    case 3:
72
1.52k
      if (hash) {
73
1.44k
        void *key;
74
1.44k
        void *value;
75
1.44k
        char arr[KEY_SIZE];
76
1.44k
        memset(arr, 0, KEY_SIZE);
77
1.44k
        fuzz_get_random_data(arr, KEY_SIZE);
78
1.44k
        key = (void *)arr;
79
1.44k
        if (!hash_lookup(hash, key)) {
80
1.33k
          generic_ssizet = fuzz_randomizer_get_int(0, 0xfffffff);
81
1.33k
          value = (void *)generic_ssizet;
82
1.33k
          hash_add(hash, key, value, false);
83
1.33k
        }
84
1.44k
      }
85
1.52k
      break;
86
104
    case 4:
87
104
      if (hash) {
88
61
        hash_n_elements(hash);
89
61
      }
90
104
      break;
91
107
    case 5:
92
107
      if (hash) {
93
66
        hash_n_buckets(hash);
94
66
      }
95
107
      break;
96
116
    case 6:
97
116
      if (hash) {
98
73
        uint32_t hv;
99
73
        generic_ssizet = fuzz_randomizer_get_int(0, 0xfffffff);
100
73
        hv = generic_ssizet;
101
73
        hash_bucket(hash, hv);
102
73
      }
103
116
      break;
104
550
    case 7:
105
550
      if (hash) {
106
440
        void *key;
107
440
        char arr[KEY_SIZE];
108
440
        memset(arr, 0, KEY_SIZE);
109
440
        fuzz_get_random_data(arr, KEY_SIZE);
110
440
        key = (void *)arr;
111
440
        hash_remove(hash, key);
112
440
      }
113
550
      break;
114
485
    case 8:
115
485
      if (hash) {
116
441
        void *value;
117
441
        generic_ssizet = fuzz_randomizer_get_int(0, 0xfffffff);
118
441
        value = (void *)generic_ssizet;
119
441
        hash_remove_by_value(hash, value);
120
441
      }
121
485
    default:
122
485
      break;
123
8.79k
    }
124
8.79k
  }
125
126
528
  if (hash) {
127
511
    hash_free(hash);
128
511
  }
129
130
528
  gc_free(&gc);
131
132
528
  fuzz_random_destroy();
133
134
528
  return 0;
135
528
}