/src/augeas/augeas_fa_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | # Copyright 2020 Google Inc. |
3 | | # |
4 | | # Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | # you may not use this file except in compliance with the License. |
6 | | # You may obtain a copy of the License at |
7 | | # |
8 | | # http://www.apache.org/licenses/LICENSE-2.0 |
9 | | # |
10 | | # Unless required by applicable law or agreed to in writing, software |
11 | | # distributed under the License is distributed on an "AS IS" BASIS, |
12 | | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | # See the License for the specific language governing permissions and |
14 | | # limitations under the License. |
15 | | # |
16 | | ################################################################################ |
17 | | */ |
18 | | |
19 | | |
20 | | |
21 | | #include <stdio.h> |
22 | | #include <stdint.h> |
23 | | #include <string.h> |
24 | | #include <stdlib.h> |
25 | | |
26 | | // Augea includes |
27 | | #include "augeas.h" |
28 | | #include "config.h" |
29 | | #include "fa.h" |
30 | | #include "internal.h" |
31 | | |
32 | | |
33 | | /* |
34 | | * FA fuzzer. |
35 | | */ |
36 | | extern "C" |
37 | 0 | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size){ |
38 | 0 | if(Size<3){ |
39 | 0 | return 0; |
40 | 0 | } |
41 | 0 | char *new_str = (char *)malloc(Size+1); |
42 | 0 | if (new_str == NULL){ |
43 | 0 | return 0; |
44 | 0 | } |
45 | 0 | memcpy(new_str, Data, Size); |
46 | 0 | new_str[Size] = '\0'; |
47 | 0 | int intSize = (int)Size; |
48 | 0 | char *s; |
49 | | |
50 | |
|
51 | 0 | size_t len; |
52 | 0 | int r = fa_expand_nocase(new_str, intSize, &s, &len); |
53 | | |
54 | 0 | struct fa *fa2 = NULL; |
55 | 0 | int r2 = fa_compile(new_str, intSize, &fa2); |
56 | |
|
57 | 0 | struct fa *fa1 = NULL; |
58 | 0 | fa_compile(&new_str[1], intSize, &fa1); |
59 | 0 | struct fa *fa_min; |
60 | 0 | fa_min = fa_minus(fa1, fa2); |
61 | | |
62 | 0 | if (fa2 != NULL) |
63 | 0 | { |
64 | 0 | char* word = NULL; |
65 | 0 | size_t word_len = 0; |
66 | 0 | fa_example(fa2, &word, &word_len); |
67 | | |
68 | 0 | if(word != NULL) |
69 | 0 | free(word); |
70 | |
|
71 | 0 | fa_json(stdout, fa2); |
72 | 0 | fa_minimize(fa2); |
73 | 0 | fa_dot(stdout, fa2); |
74 | 0 | } |
75 | |
|
76 | 0 | struct fa *fa_b = fa_make_basic(intSize); |
77 | | |
78 | | // cleanup |
79 | 0 | if (s != NULL) free(s); |
80 | 0 | if (new_str != NULL) free(new_str); |
81 | 0 | if (fa_b != NULL) fa_free(fa_b); |
82 | 0 | if (fa_min != NULL) fa_free(fa_min); |
83 | 0 | if (fa1 != NULL) fa_free(fa1); |
84 | 0 | if (fa2 != NULL) fa_free(fa2); |
85 | 0 | return 0; |
86 | 0 | } |