Skip to content

Commit 249b40f

Browse files
authored
Fix stdin for casr-libafl (#243)
1 parent 840145d commit 249b40f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

casr/src/bin/casr-libfuzzer.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ fn main() -> Result<()> {
177177
bail!("casr-gdb-args option is provided with incompatible tool. This option can be used with casr-san or casr-gdb.");
178178
}
179179

180-
// Get input file argument index.
181-
let at_index = if let Some(idx) = argv.iter().skip(1).position(|s| s.contains("@@")) {
182-
idx + 1
183-
} else {
184-
argv.push("@@");
185-
argv.len() - 1
186-
};
187-
188180
let crash_files: HashMap<String, PathBuf> = fs::read_dir(input_dir)?
189181
.flatten()
190182
.map(|p| p.path())
@@ -193,6 +185,7 @@ fn main() -> Result<()> {
193185
.collect();
194186

195187
// Determine crash directory format for libfuzzer or LibAFL.
188+
let mut is_libafl_based = false;
196189
let crash_filter = if crash_files
197190
.iter()
198191
.any(|(fname, _)| fname.starts_with("crash-") || fname.starts_with("leak-"))
@@ -201,9 +194,20 @@ fn main() -> Result<()> {
201194
arg.0.starts_with("crash-") || arg.0.starts_with("leak-")
202195
}
203196
} else {
197+
is_libafl_based = true;
204198
|arg: &(&std::string::String, &PathBuf)| !arg.0.starts_with(".")
205199
};
206200

201+
// Get input file argument index.
202+
let at_index = if let Some(idx) = argv.iter().skip(1).position(|s| s.contains("@@")) {
203+
Some(idx + 1)
204+
} else if is_libafl_based {
205+
None
206+
} else {
207+
argv.push("@@");
208+
Some(argv.len() - 1)
209+
};
210+
207211
// Get all crashes.
208212
let crashes: HashMap<String, CrashInfo> = crash_files
209213
.iter()
@@ -215,7 +219,7 @@ fn main() -> Result<()> {
215219
path: p.to_path_buf(),
216220
target_args: argv.iter().map(|x| x.to_string()).collect(),
217221
envs: envs.clone(),
218-
at_index: Some(at_index),
222+
at_index,
219223
casr_tool: tool_path.clone(),
220224
},
221225
)

0 commit comments

Comments
 (0)