1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239use std::collections::HashMap;
use config::Config;
use crate::apps::custom::CustomStruct;
use crate::broken_files::LANGS;
use crate::common::CheckGroupFileMode;
use crate::obj::ProgramConfig;
pub const TIMEOUT_MESSAGE: &str = "timeout: sending signal";
#[derive(Clone, Debug)]
pub struct Setting {
pub name: String,
pub loop_number: u32,
pub broken_files_for_each_file: u32,
pub minimize_output: bool,
pub minimization_attempts: u32,
pub minimization_time: u32,
pub minimization_repeat: bool,
pub minimization_attempts_with_signal_timeout: u32,
pub remove_non_crashing_items_from_broken_files: bool,
pub temp_folder: String,
pub extensions: Vec<String>,
pub broken_files_dir: String,
pub valid_input_files_dir: String,
pub temp_possible_broken_files_dir: String,
pub debug_print_results: bool,
pub timeout: usize,
pub timeout_group: usize,
pub allowed_signal_statuses: Vec<i32>,
pub allowed_error_statuses: Vec<i32>,
pub debug_print_broken_files_creator: bool,
pub max_collected_files: usize,
pub check_if_file_is_parsable: bool,
pub max_file_size_limit: u64,
pub grouping: u32,
pub debug_executed_commands: bool,
pub check_for_stability: bool,
pub stability_runs: u32,
pub custom_items: CustomItems,
pub custom_folder_path: String,
pub ignore_file_if_contains_searched_items: bool,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum StabilityMode {
None,
ConsoleOutput,
FileContent,
OutputContent,
}
#[derive(Clone, Debug)]
pub struct CustomItems {
pub group_mode: CheckGroupFileMode,
pub command_parts: Vec<String>,
pub group_command_parts: Vec<String>,
pub search_items: Vec<String>,
pub ignored_items: Vec<String>,
pub file_type: LANGS,
pub stability_mode: StabilityMode,
}
fn get_stability_mode(tool_hashmap: &HashMap<String, String>) -> StabilityMode {
match tool_hashmap["stability_mode"].as_str() {
"none" => StabilityMode::None,
"console_output" => StabilityMode::ConsoleOutput,
"file_content" => StabilityMode::FileContent,
"output_content" => StabilityMode::OutputContent,
_ => panic!("Invalid stability mode {}", tool_hashmap["stability_mode"]),
}
}
pub(crate) fn process_custom_struct(
general: &HashMap<String, String>,
tool_hashmap: &HashMap<String, String>,
) -> CustomItems {
let stability_mode = get_stability_mode(tool_hashmap);
let group_mode = match tool_hashmap["group_mode"].as_str() {
"none" => CheckGroupFileMode::None,
"by_files" => CheckGroupFileMode::ByFilesGroup,
"by_group" => CheckGroupFileMode::ByFolder,
_ => panic!("Invalid group mode {}", tool_hashmap["group_mode"]),
};
let mut command_parts = Vec::new();
let timeout_time: u32 = general["timeout"].parse().unwrap();
if timeout_time != 0 {
command_parts.push("timeout".to_string());
command_parts.push("-v".to_string());
command_parts.push(timeout_time.to_string());
}
let mut group_command_parts = Vec::new();
let timeout_time_group: u32 = general["timeout_group"].parse().unwrap();
if timeout_time_group != 0 {
group_command_parts.push("timeout".to_string());
group_command_parts.push("-v".to_string());
group_command_parts.push(timeout_time_group.to_string());
}
if tool_hashmap["command"]
.split('|')
.filter_map(|e| {
let r = e.trim();
if r.is_empty() { None } else { Some(r) }
})
.count()
== 0
|| !tool_hashmap["command"].contains("FILE_PATHS_TO_PROVIDE")
{
panic!("No command found in the custom tool or FILE_PATHS_TO_PROVIDE is not found in the command");
}
command_parts.extend(tool_hashmap["command"].split('|').map(str::to_string));
group_command_parts.extend(tool_hashmap["command"].split('|').map(str::to_string));
let search_item_keys: Vec<_> = tool_hashmap
.iter()
.filter_map(|(key, value)| {
if key.starts_with("search_item_") && !value.trim().is_empty() {
Some(key)
} else {
None
}
})
.cloned()
.collect();
let search_items: Vec<_> = search_item_keys.iter().map(|e| tool_hashmap[e].clone()).collect();
assert!(!search_items.is_empty(), "No search items found in the custom tool");
let ignored_item_keys: Vec<_> = tool_hashmap
.iter()
.filter_map(|(key, value)| {
if key.starts_with("ignored_item_") && !value.trim().is_empty() {
Some(key)
} else {
None
}
})
.cloned()
.collect();
let ignored_items = ignored_item_keys.iter().map(|e| tool_hashmap[e].clone()).collect();
let file_type = match tool_hashmap["file_type"].as_str() {
"text" => LANGS::TEXT,
"binary" => LANGS::BINARY,
"js" => LANGS::JAVASCRIPT,
"go" => LANGS::GO,
"rust" => LANGS::RUST,
"lua" => LANGS::LUA,
"python" => LANGS::PYTHON,
"slint" => LANGS::SLINT,
"jsvuesvelte" => LANGS::JSVUESVELTE,
"svg" => LANGS::SVG,
"gdscript" => LANGS::GDSCRIPT,
_ => panic!("Invalid file type {}", tool_hashmap["file_type"]),
};
CustomItems {
group_mode,
command_parts,
group_command_parts,
search_items,
ignored_items,
file_type,
stability_mode,
}
}
pub(crate) fn load_settings() -> Setting {
let settings = Config::builder()
.add_source(config::File::with_name("fuzz_settings"))
.build()
.unwrap();
let config = settings
.try_deserialize::<HashMap<String, HashMap<String, String>>>()
.unwrap();
let general = config["general"].clone();
let current_mode_string = general["current_mode"].clone();
let curr_setting = config[¤t_mode_string].clone();
let name = curr_setting["name"].clone();
let extensions = curr_setting["extensions"]
.split(',')
.map(str::trim)
.filter_map(|e| if e.is_empty() { None } else { Some(format!(".{e}")) })
.collect();
let remove_non_crashing_items_from_broken_files =
general["remove_non_crashing_items_from_broken_files"].parse().unwrap();
let grouping = general["grouping"].parse().unwrap();
let debug_executed_commands = general["debug_executed_commands"].parse().unwrap();
let custom_items = process_custom_struct(&general, &curr_setting);
Setting {
name,
loop_number: general["loop_number"].parse().unwrap(),
broken_files_for_each_file: general["broken_files_for_each_file"].parse().unwrap(),
minimize_output: general["minimize_output"].parse().unwrap(),
minimization_time: general["minimization_time"].parse().unwrap(),
minimization_attempts: general["minimization_attempts"].parse().unwrap(),
minimization_repeat: general["minimization_repeat"].parse().unwrap(),
minimization_attempts_with_signal_timeout: general["minimization_attempts_with_signal_timeout"]
.parse()
.unwrap(),
remove_non_crashing_items_from_broken_files,
extensions,
timeout: general["timeout"].parse().unwrap(),
timeout_group: general["timeout_group"].parse().unwrap(),
broken_files_dir: curr_setting["broken_files_dir"].parse().unwrap(),
valid_input_files_dir: curr_setting["valid_input_files_dir"].parse().unwrap(),
temp_possible_broken_files_dir: general["temp_possible_broken_files_dir"].parse().unwrap(),
debug_print_results: general["debug_print_results"].parse().unwrap(),
allowed_error_statuses: general["allowed_error_statuses"]
.split(',')
.map(|e| e.parse().unwrap())
.collect(),
debug_print_broken_files_creator: general["debug_print_broken_files_creator"].parse().unwrap(),
max_collected_files: general["max_collected_files"].parse().unwrap(),
temp_folder: general["temp_folder"].clone(),
check_if_file_is_parsable: general["check_if_file_is_parsable"].parse().unwrap(),
grouping,
debug_executed_commands,
custom_items,
check_for_stability: general["check_for_stability"].parse().unwrap(),
stability_runs: general["stability_runs"].parse().unwrap(),
custom_folder_path: general["custom_folder_path"].clone(),
ignore_file_if_contains_searched_items: general["ignore_file_if_contains_searched_items"].parse().unwrap(),
max_file_size_limit: general["max_file_size_limit"].parse().unwrap(),
allowed_signal_statuses: general["allowed_signal_statuses"]
.split(',')
.filter(|e| !e.trim().is_empty())
.map(|e| e.trim().parse().unwrap())
.collect(),
}
}
pub(crate) fn get_object(settings: Setting) -> Box<dyn ProgramConfig> {
let custom_items = settings.custom_items.clone();
Box::new(CustomStruct { settings, custom_items })
}