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"
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)37 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size){
38 if(Size<3){
39 return 0;
40 }
41 char *new_str = (char *)malloc(Size+1);
42 if (new_str == NULL){
43 return 0;
44 }
45 memcpy(new_str, Data, Size);
46 new_str[Size] = '\0';
47 int intSize = (int)Size;
48 char *s;
49
50
51 size_t len;
52 int r = fa_expand_nocase(new_str, intSize, &s, &len);
53
54 struct fa *fa2 = NULL;
55 int r2 = fa_compile(new_str, intSize, &fa2);
56
57 struct fa *fa1 = NULL;
58 fa_compile(&new_str[1], intSize, &fa1);
59 struct fa *fa_min;
60 fa_min = fa_minus(fa1, fa2);
61
62 if (fa2 != NULL)
63 {
64 char* word = NULL;
65 size_t word_len = 0;
66 fa_example(fa2, &word, &word_len);
67
68 if(word != NULL)
69 free(word);
70
71 fa_json(stdout, fa2);
72 fa_minimize(fa2);
73 fa_dot(stdout, fa2);
74 }
75
76 struct fa *fa_b = fa_make_basic(intSize);
77
78 // cleanup
79 if (s != NULL) free(s);
80 if (new_str != NULL) free(new_str);
81 if (fa_b != NULL) fa_free(fa_b);
82 if (fa_min != NULL) fa_free(fa_min);
83 if (fa1 != NULL) fa_free(fa1);
84 if (fa2 != NULL) fa_free(fa2);
85 return 0;
86 }
87