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 | | |
14 | | #include "config.h" |
15 | | #include "syshead.h" |
16 | | #include "misc.h" |
17 | | #include "buffer.h" |
18 | | |
19 | | #include "fuzz_randomizer.h" |
20 | | |
21 | 564 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
22 | 564 | fuzz_random_init(data, size); |
23 | | |
24 | 564 | struct gc_arena gc; |
25 | 564 | struct env_set *es; |
26 | 564 | gc = gc_new(); |
27 | 564 | es = env_set_create(&gc); |
28 | | |
29 | 564 | int total_to_fuzz = fuzz_randomizer_get_int(1, 9); |
30 | 3.81k | for (int i = 0; i <total_to_fuzz; i++) { |
31 | 3.25k | int type = fuzz_randomizer_get_int(0, 3); |
32 | 3.25k | char *tmp1 = get_random_string(); |
33 | 3.25k | char *tmp2 = get_random_string(); |
34 | | |
35 | 3.25k | switch (type) { |
36 | 2.17k | case 0: |
37 | 2.17k | env_set_del(es, tmp1); |
38 | 2.17k | break; |
39 | 419 | case 1: |
40 | 419 | env_set_add(es, tmp1); |
41 | 419 | break; |
42 | 218 | case 2: |
43 | 218 | env_set_get(es, tmp1); |
44 | 218 | break; |
45 | 437 | case 3: |
46 | 437 | if (strlen(tmp1) > 1 && strlen(tmp2) > 1) { |
47 | 280 | setenv_str(es, tmp2, tmp1); |
48 | 280 | } |
49 | 437 | break; |
50 | 0 | default: |
51 | 0 | sanitize_control_message(tmp1, &gc); |
52 | 3.25k | } |
53 | 3.25k | free(tmp1); |
54 | 3.25k | free(tmp2); |
55 | 3.25k | } |
56 | | |
57 | 564 | env_set_destroy(es); |
58 | 564 | gc_free(&gc); |
59 | | |
60 | 564 | fuzz_random_destroy(); |
61 | 564 | return 0; |
62 | 564 | } |