Coverage Report

Created: 2023-05-30 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
958
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
22
958
  fuzz_random_init(data, size);
23
24
958
  struct gc_arena gc;
25
958
  struct env_set *es;
26
958
  gc = gc_new();
27
958
  es = env_set_create(&gc);
28
29
958
  int total_to_fuzz = fuzz_randomizer_get_int(1, 9);
30
6.08k
  for (int i = 0; i <total_to_fuzz; i++) {
31
5.12k
    int type = fuzz_randomizer_get_int(0, 5);
32
5.12k
    char *tmp1 = get_random_string();
33
5.12k
    char *tmp2 = get_random_string();
34
35
5.12k
    switch (type) {
36
3.37k
    case 0:
37
3.37k
      env_set_del(es, tmp1);
38
3.37k
      break;
39
344
    case 1:
40
344
      env_set_add(es, tmp1);
41
344
      break;
42
203
    case 2:
43
203
      env_set_get(es, tmp1);
44
203
      break;
45
290
    case 3:
46
290
      if (strlen(tmp1) > 1 && strlen(tmp2) > 1) {
47
204
        setenv_str(es, tmp2, tmp1);
48
204
      }
49
290
      break;
50
167
    case 4:
51
167
      hostname_randomize(tmp1, &gc);
52
167
      break;
53
743
    case 5:
54
743
      if (strlen(tmp1) > 0) {
55
695
        get_auth_challenge(tmp1, &gc);
56
695
      }
57
743
      break;
58
0
    default:
59
0
      sanitize_control_message(tmp1, &gc);
60
5.12k
    }
61
5.12k
    free(tmp1);
62
5.12k
    free(tmp2);
63
5.12k
  }
64
65
958
  env_set_destroy(es);
66
958
  gc_free(&gc);
67
68
958
  fuzz_random_destroy();
69
958
  return 0;
70
958
}