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

optionally ignore dotfiles in syncdir monitors #741

Merged
merged 5 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/agent/onefuzz-agent/src/tasks/fuzz/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl GeneratorTask {
self.config.ensemble_sync_delay,
);

let crash_dir_monitor = self.config.crashes.monitor_results(new_result);
let crash_dir_monitor = self.config.crashes.monitor_results(new_result, false);

let fuzzer = self.fuzzing_loop(hb_client);

Expand Down
4 changes: 2 additions & 2 deletions src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl LibFuzzerFuzzTask {

// To be scheduled.
let resync = self.continuous_sync_inputs();
let new_inputs = self.config.inputs.monitor_results(new_coverage);
let new_crashes = self.config.crashes.monitor_results(new_result);
let new_inputs = self.config.inputs.monitor_results(new_coverage, true);
let new_crashes = self.config.crashes.monitor_results(new_result, true);

let (stats_sender, stats_receiver) = mpsc::unbounded_channel();
let report_stats = report_runtime_stats(self.workers() as usize, stats_receiver, hb_client);
Expand Down
4 changes: 2 additions & 2 deletions src/agent/onefuzz-agent/src/tasks/fuzz/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn spawn(config: SupervisorConfig) -> Result<(), Error> {
url: config.crashes.url.clone(),
};
crashes.init().await?;
let monitor_crashes = crashes.monitor_results(new_result);
let monitor_crashes = crashes.monitor_results(new_result, false);

// setup reports
let reports_dir = tempdir()?;
Expand Down Expand Up @@ -111,7 +111,7 @@ pub async fn spawn(config: SupervisorConfig) -> Result<(), Error> {
delay_with_jitter(delay).await;
}
}
let monitor_inputs = inputs.monitor_results(new_coverage);
let monitor_inputs = inputs.monitor_results(new_coverage, false);
let continuous_sync_task = inputs.continuous_sync(Pull, config.ensemble_sync_delay);

let process = start_supervisor(
Expand Down
17 changes: 14 additions & 3 deletions src/agent/onefuzz/src/syncdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl SyncedDir {
}
}

async fn file_monitor_event(&self, event: Event) -> Result<()> {
async fn file_monitor_event(&self, event: Event, ignore_dotfiles: bool) -> Result<()> {
debug!("monitoring {}", self.path.display());
let mut monitor = DirectoryMonitor::new(self.path.clone());
monitor.start()?;
Expand All @@ -167,6 +167,10 @@ impl SyncedDir {
let file_name = item
.file_name()
.ok_or_else(|| anyhow!("invalid file path"))?;
if ignore_dotfiles && file_name.to_string_lossy().starts_with('.') {
continue;
}

event!(event.clone(); EventData::Path = file_name.to_string_lossy());
let destination = path.join(file_name);
if let Err(err) = fs::copy(&item, &destination).await {
Expand All @@ -188,6 +192,12 @@ impl SyncedDir {
let mut uploader = BlobUploader::new(self.url.url().clone());

while let Some(item) = monitor.next().await {
let file_name = item
.file_name()
.ok_or_else(|| anyhow!("invalid file path"))?;
if ignore_dotfiles && file_name.to_string_lossy().starts_with('.') {
continue;
}
event!(event.clone(); EventData::Path = item.display().to_string());

if let Err(err) = uploader.upload(item.clone()).await {
Expand Down Expand Up @@ -221,7 +231,7 @@ impl SyncedDir {
/// The intent of this is to support use cases where we usually want a directory
/// to be initialized, but a user-supplied binary, (such as AFL) logically owns
/// a directory, and may reset it.
pub async fn monitor_results(&self, event: Event) -> Result<()> {
pub async fn monitor_results(&self, event: Event, ignore_dotfiles: bool) -> Result<()> {
loop {
debug!("waiting to monitor {}", self.path.display());

Expand All @@ -231,7 +241,8 @@ impl SyncedDir {
}

debug!("starting monitor for {}", self.path.display());
self.file_monitor_event(event.clone()).await?;
self.file_monitor_event(event.clone(), ignore_dotfiles)
.await?;
}
}
}
Expand Down