Coverage Report

Created: 2025-08-31 07:02

/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
599
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
22
599
  fuzz_random_init(data, size);
23
24
599
  struct gc_arena gc;
25
599
  struct env_set *es;
26
599
  gc = gc_new();
27
599
  es = env_set_create(&gc);
28
29
599
  int total_to_fuzz = fuzz_randomizer_get_int(1, 9);
30
3.98k
  for (int i = 0; i <total_to_fuzz; i++) {
31
3.38k
    int type = fuzz_randomizer_get_int(0, 4);
32
3.38k
    char *tmp1 = get_random_string();
33
3.38k
    char *tmp2 = get_random_string();
34
35
3.38k
    switch (type) {
36
2.18k
    case 0:
37
2.18k
      env_set_del(es, tmp1);
38
2.18k
      break;
39
368
    case 1:
40
368
      env_set_add(es, tmp1);
41
368
      break;
42
274
    case 2:
43
274
      env_set_get(es, tmp1);
44
274
      break;
45
362
    case 3:
46
362
      if (strlen(tmp1) > 1 && strlen(tmp2) > 1) {
47
247
        setenv_str(es, tmp2, tmp1);
48
247
      }
49
362
      break;
50
192
    case 4:
51
192
      hostname_randomize(tmp1, &gc);
52
192
      break;
53
0
    default:
54
0
      sanitize_control_message(tmp1, &gc);
55
3.38k
    }
56
3.38k
    free(tmp1);
57
3.38k
    free(tmp2);
58
3.38k
  }
59
60
599
  env_set_destroy(es);
61
599
  gc_free(&gc);
62
63
599
  fuzz_random_destroy();
64
599
  return 0;
65
599
}