Skip to content

Commit

Permalink
Print a warning about not passing a --sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Mar 9, 2022
1 parent fec1e28 commit 6a63217
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
12 changes: 5 additions & 7 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ pub struct BuildOptions {
short = "s",
long = "sanitizer",
possible_values(&["address", "leak", "memory", "thread", "none"]),
default_value = "none",
)]
/// Use a specific sanitizer
pub sanitizer: Sanitizer,
pub sanitizer: Option<Sanitizer>,

#[structopt(long = "build-std")]
/// Pass -Zbuild-std to Cargo, which will build the standard library with all the build
Expand Down Expand Up @@ -180,9 +179,8 @@ impl stdfmt::Display for BuildOptions {
write!(f, " --features={}", feature)?;
}

match self.sanitizer {
Sanitizer::None => {}
_ => write!(f, " --sanitizer={}", self.sanitizer)?,
if let Some(sanitizer) = self.sanitizer {
write!(f, " --sanitizer={}", sanitizer)?;
}

if self.triple != crate::utils::default_target() {
Expand Down Expand Up @@ -236,7 +234,7 @@ mod test {
no_default_features: false,
all_features: false,
features: None,
sanitizer: Sanitizer::None,
sanitizer: None,
build_std: false,
triple: String::from(crate::utils::default_target()),
unstable_flags: Vec::new(),
Expand Down Expand Up @@ -278,7 +276,7 @@ mod test {
..default_opts.clone()
},
BuildOptions {
sanitizer: Sanitizer::None,
sanitizer: None,
..default_opts.clone()
},
BuildOptions {
Expand Down
21 changes: 12 additions & 9 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl FuzzProject {
for flag in &build.unstable_flags {
cmd.arg("-Z").arg(flag);
}
if let Sanitizer::Memory = build.sanitizer {
if let Some(Sanitizer::Memory) = build.sanitizer {
cmd.arg("-Z").arg("build-std");
}

Expand All @@ -182,16 +182,19 @@ impl FuzzProject {
}

match build.sanitizer {
Sanitizer::None => {}
Sanitizer::Memory => {
Some(Sanitizer::None) => {}
Some(Sanitizer::Memory) => {
// Memory sanitizer requires more flags to function than others:
// https://doc.rust-lang.org/unstable-book/compiler-flags/sanitizer.html#memorysanitizer
rustflags.push_str(" -Zsanitizer=memory -Zsanitizer-memory-track-origins")
}
_ => rustflags.push_str(&format!(
" -Zsanitizer={sanitizer}",
sanitizer = build.sanitizer
)),
Some(sanitizer) => rustflags.push_str(&format!(" -Zsanitizer={}", sanitizer)),
None => {
println!(
"warning: Omitting the --sanitizer flag used to mean --sanitizer=address. \
It now means --sanitizer=none."
);
}
}
if build.triple.contains("-linux-") {
rustflags.push_str(" -Cllvm-args=-sanitizer-coverage-stack-depth");
Expand Down Expand Up @@ -226,7 +229,7 @@ impl FuzzProject {
// options, so users can still provide their own options to e.g. disable
// the leak sanitizer. Options are colon-separated.
match build.sanitizer {
Sanitizer::Address => {
Some(Sanitizer::Address) => {
let mut asan_opts = env::var("ASAN_OPTIONS").unwrap_or_default();
if !asan_opts.is_empty() {
asan_opts.push(':');
Expand All @@ -235,7 +238,7 @@ impl FuzzProject {
cmd.env("ASAN_OPTIONS", asan_opts);
}

Sanitizer::Thread => {
Some(Sanitizer::Thread) => {
let mut tsan_opts = env::var("TSAN_OPTIONS").unwrap_or_default();
if !tsan_opts.is_empty() {
tsan_opts.push(':');
Expand Down

0 comments on commit 6a63217

Please sign in to comment.