Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate coverage, artifacts and corpus dirs with CACHEDIR.TAG #369

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Released YYYY-MM-DD.

### Added
- creation of `CACHEDIR.TAG` inside `artifacts`, `corpus` and `coverage` directories

* TODO (or remove section if none)

Expand Down
41 changes: 41 additions & 0 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ use std::{
};

const DEFAULT_FUZZ_DIR: &str = "fuzz";
const CACHE_TAG_HEADER: &[u8; 194] = b"Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo-fuzz.
# For information about cache directory tags, see:
# http://www.brynosaurus.com/cachedir/
";

pub struct FuzzProject {
/// The project with fuzz targets
Expand Down Expand Up @@ -809,6 +814,18 @@ impl FuzzProject {
fs::create_dir_all(&coverage_raw).with_context(|| {
format!("could not make a coverage directory at {:?}", coverage_raw)
})?;
// (re)create a CACHEDIR.TAG
let mut cache_path = coverage_data
.parent()
.expect("path to coverage must contain at least coverage/<target>!")
.to_owned();
cache_path.push("CACHEDIR.TAG");
let mut cache_file = fs::File::create(&cache_path)
.with_context(|| format!("could not create a CACHEDIR.TAG at {:?}", cache_path))?;
cache_file
.write_all(CACHE_TAG_HEADER)
.with_context(|| format!("could not write cache tag contents to {:?}", cache_path))?;

Ok((coverage_raw, coverage_data))
}

Expand All @@ -818,6 +835,18 @@ impl FuzzProject {
p.push(target);
fs::create_dir_all(&p)
.with_context(|| format!("could not make a corpus directory at {:?}", p))?;
// (re)create a CACHEDIR.TAG
let mut cache_path = p
.parent()
.expect("path to corpus must contain at least corpus/<target>!")
.to_owned();
cache_path.push("CACHEDIR.TAG");
let mut cache_file = fs::File::create(&cache_path)
.with_context(|| format!("could not create a CACHEDIR.TAG at {:?}", cache_path))?;
cache_file
.write_all(CACHE_TAG_HEADER)
.with_context(|| format!("could not write cache tag contents to {:?}", cache_path))?;

Ok(p)
}

Expand All @@ -833,6 +862,18 @@ impl FuzzProject {
fs::create_dir_all(&p)
.with_context(|| format!("could not make a artifact directory at {:?}", p))?;

// (re)create a CACHEDIR.TAG
let mut cache_path = p
.parent()
.expect("path to artifacts must contain at least artifacts/<target>!")
.to_owned();
cache_path.push("CACHEDIR.TAG");
let mut cache_file = fs::File::create(&cache_path)
.with_context(|| format!("could not create a CACHEDIR.TAG at {:?}", cache_path))?;
cache_file
.write_all(CACHE_TAG_HEADER)
.with_context(|| format!("could not write cache tag contents to {:?}", cache_path))?;

Ok(p)
}

Expand Down
Loading