Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Simplify more
Browse files Browse the repository at this point in the history
  • Loading branch information
Porges authored Jul 5, 2023
1 parent 5bf8c71 commit 9ca4d8f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
7 changes: 7 additions & 0 deletions src/agent/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/agent/onefuzz-task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ azure_storage_blobs = { version = "0.12", default-features = false, features = [
] }

flexi_logger = "0.25"
cascade = "1.0.1"

[dev-dependencies]
pretty_assertions = "1.3"
36 changes: 3 additions & 33 deletions src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer/generic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use std::path::PathBuf;

use anyhow::Result;
use async_trait::async_trait;
use cascade::cascade;
use onefuzz::libfuzzer::LibFuzzer;

use crate::tasks::fuzz::libfuzzer::common;
Expand Down Expand Up @@ -50,7 +49,8 @@ impl common::LibFuzzerType for GenericLibFuzzer {
// The .local file is an empty file that tells DLL resolution to consider the same directory,
// even for system (or KnownDLL) files.
// See: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-redirection#how-to-redirect-dlls-for-unpackaged-apps
let dotlocal_file = add_dotlocal_extension(target_exe);
let dotlocal_file = cascade! {target_exe; ..push(".local");};

if let Err(e) = tokio::fs::write(dotlocal_file, &[]).await {
// ignore already-exists error, report anything else
if e.kind() != std::io::ErrorKind::AlreadyExists {
Expand All @@ -64,35 +64,5 @@ impl common::LibFuzzerType for GenericLibFuzzer {
}
}

fn add_dotlocal_extension(mut path: PathBuf) -> PathBuf {
path.push(".local");
path
}

pub type Config = common::Config<GenericLibFuzzer>;
pub type LibFuzzerFuzzTask = common::LibFuzzerFuzzTask<GenericLibFuzzer>;

#[cfg(test)]
mod test {
use std::path::PathBuf;

use super::add_dotlocal_extension;

#[test]
fn dotlocal_with_extension() {
let path = PathBuf::from("executable.exe");
assert_eq!(
PathBuf::from("executable.exe.local"),
add_dotlocal_extension(path)
);
}

#[test]
fn dotlocal_without_extension() {
let path = PathBuf::from("executable");
assert_eq!(
PathBuf::from("executable.local"),
add_dotlocal_extension(path)
);
}
}

0 comments on commit 9ca4d8f

Please sign in to comment.