Skip to content

Commit

Permalink
Simplify copy_afl_llvm_plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Nov 12, 2023
1 parent 785db30 commit ad15c2e
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions cargo-afl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,25 @@ fn build_afl_llvm_runtime(work_dir: &Path, base: Option<&Path>) {

fn copy_afl_llvm_plugins(work_dir: &Path, base: Option<&Path>) {
// Iterate over the files in the directory.
if let Ok(entries) = work_dir.read_dir() {
for entry in entries.flatten() {
let file_name = entry.file_name();
let file_name_str = file_name.to_string_lossy();

// Get the file extension.
if let Some(extension) = file_name_str.split('.').last() {
// Only copy the files that are shared objects
if extension == "so" {
// Attempt to copy the shared object file.
std::fs::copy(
work_dir.join(&file_name),
common::afl_llvm_dir(base).join(&file_name),
)
.unwrap_or_else(|_| {
panic!("Couldn't copy shared object file {file_name_str}",)
});
}
for result in work_dir.read_dir().unwrap() {
let entry = result.unwrap();
let file_name = entry.file_name();
let file_name_str = file_name.to_string_lossy();

// Get the file extension.
if let Some((_, extension)) = file_name_str.rsplit_once('.') {
// Only copy the files that are shared objects
if extension == "so" {
// Attempt to copy the shared object file.
std::fs::copy(
work_dir.join(&file_name),
common::afl_llvm_dir(base).join(&file_name),
)
.unwrap_or_else(|error| {
panic!("Couldn't copy shared object file {file_name:?}: {error}")
});
}
}
} else {
eprintln!("Failed to read the work directory. Aborting.");
}
}

Expand Down

0 comments on commit ad15c2e

Please sign in to comment.