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