Coverage Report

Created: 2025-07-23 06:54

/src/fuzz_misc.c
Line
Count
Source (jump to first uncovered line)
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
14
#include "config.h"
15
#include "syshead.h"
16
#include "misc.h"
17
#include "buffer.h"
18
19
#include "fuzz_randomizer.h"
20
21
605
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
22
605
  fuzz_random_init(data, size);
23
24
605
  struct gc_arena gc;
25
605
  struct env_set *es;
26
605
  gc = gc_new();
27
605
  es = env_set_create(&gc);
28
29
605
  int total_to_fuzz = fuzz_randomizer_get_int(1, 9);
30
4.16k
  for (int i = 0; i <total_to_fuzz; i++) {
31
3.56k
    int type = fuzz_randomizer_get_int(0, 4);
32
3.56k
    char *tmp1 = get_random_string();
33
3.56k
    char *tmp2 = get_random_string();
34
35
3.56k
    switch (type) {
36
2.38k
    case 0:
37
2.38k
      env_set_del(es, tmp1);
38
2.38k
      break;
39
340
    case 1:
40
340
      env_set_add(es, tmp1);
41
340
      break;
42
268
    case 2:
43
268
      env_set_get(es, tmp1);
44
268
      break;
45
370
    case 3:
46
370
      if (strlen(tmp1) > 1 && strlen(tmp2) > 1) {
47
235
        setenv_str(es, tmp2, tmp1);
48
235
      }
49
370
      break;
50
201
    case 4:
51
201
      hostname_randomize(tmp1, &gc);
52
201
      break;
53
0
    default:
54
0
      sanitize_control_message(tmp1, &gc);
55
3.56k
    }
56
3.56k
    free(tmp1);
57
3.56k
    free(tmp2);
58
3.56k
  }
59
60
605
  env_set_destroy(es);
61
605
  gc_free(&gc);
62
63
605
  fuzz_random_destroy();
64
605
  return 0;
65
605
}