From 9ca4d8f618d89d5514792646ffa6707fcd79fc9c Mon Sep 17 00:00:00 2001 From: George Pollard Date: Wed, 5 Jul 2023 00:37:19 +0000 Subject: [PATCH] Simplify more --- src/agent/Cargo.lock | 7 ++++ src/agent/onefuzz-task/Cargo.toml | 1 + .../src/tasks/fuzz/libfuzzer/generic.rs | 36 ++----------------- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index c765c8edaba..58d13019e3a 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -420,6 +420,12 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" +[[package]] +name = "cascade" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d499b43edbf784dd81e16f0395f5b4350a35b477da8a074251087adefc11cb52" + [[package]] name = "cassowary" version = "0.3.0" @@ -2292,6 +2298,7 @@ dependencies = [ "azure_storage", "azure_storage_blobs", "backoff", + "cascade", "chrono", "clap", "cobertura", diff --git a/src/agent/onefuzz-task/Cargo.toml b/src/agent/onefuzz-task/Cargo.toml index 31bc99cc9a4..f6cf218d942 100644 --- a/src/agent/onefuzz-task/Cargo.toml +++ b/src/agent/onefuzz-task/Cargo.toml @@ -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" diff --git a/src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer/generic.rs b/src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer/generic.rs index c7dbb0f494e..cf30e60ed1a 100644 --- a/src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer/generic.rs +++ b/src/agent/onefuzz-task/src/tasks/fuzz/libfuzzer/generic.rs @@ -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; @@ -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 { @@ -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; pub type LibFuzzerFuzzTask = common::LibFuzzerFuzzTask; - -#[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) - ); - } -}