Skip to content

Commit

Permalink
Added --target flag to cargo fuzz run. Added macOS tests.
Browse files Browse the repository at this point in the history
Fix #36. (rustc nightly supports asan and tsan starting from today)
  • Loading branch information
kennytm committed Apr 27, 2017
1 parent 8856898 commit 47563d6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
13 changes: 9 additions & 4 deletions .travis.yml
Expand Up @@ -10,13 +10,18 @@ addons:
- gcc-5
- g++-5

rust: nightly

os:
- linux
osx_image: xcode8.3

matrix:
fast_finish: true
include:
- os: linux
rust: nightly
env: CC=gcc-5 CXX=g++-5
- os: osx
rust: nightly
env: CC=gcc CXX=g++
# ^ setting them to `clang/clang++` causes a mysterious "<cstdint> not found" error.

notifications:
email: false
Expand Down
4 changes: 2 additions & 2 deletions scripts/run.sh
Expand Up @@ -3,9 +3,9 @@ PATH=$PATH:/home/travis/.cargo/bin
cd testcrate
cargo build
cargo-fuzz init
sed -i 's/\/\/.*/testcrate\:\:test_func\(data\)\;/g' fuzz/fuzzers/fuzzer_script_1.rs
sed -i'' -e 's/\/\/.*/testcrate\:\:test_func\(data\)\;/g' fuzz/fuzzers/fuzzer_script_1.rs

if CC=gcc-5 CXX=g++-5 cargo-fuzz run fuzzer_script_1 -- -runs=1000; then
if cargo-fuzz run fuzzer_script_1 -- -runs=1000; then
exit 100; # Should not succeed!
else
:;
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Expand Up @@ -53,6 +53,8 @@ fn main() {
.help("custom corpus directory or artefact files"))
.arg(Arg::with_name("ARGS").multiple(true).last(true)
.help("additional libFuzzer arguments passed to the binary"))
.arg(Arg::with_name("TRIPLE").long("target")
.help("target triple of the fuzz target"))
)
.subcommand(SubCommand::with_name("add").about("Add a new fuzz target")
.arg(Arg::with_name("TARGET").required(true)
Expand Down Expand Up @@ -166,7 +168,7 @@ impl FuzzProject {
let corpus = args.values_of_os("CORPUS");
let exec_args = args.values_of_os("ARGS")
.map(|v| v.collect::<Vec<_>>());
let target_triple = "x86_64-unknown-linux-gnu";
let target_triple = args.value_of_os("TRIPLE").unwrap_or_else(utils::default_target);

let other_flags = env::var("RUSTFLAGS").unwrap_or_default();
let mut rustflags: String = format!(
Expand Down
13 changes: 13 additions & 0 deletions src/utils.rs
@@ -1,4 +1,5 @@
use std::io::Write;
use std::ffi::OsStr;
use term;

#[allow(dead_code)]
Expand Down Expand Up @@ -33,3 +34,15 @@ pub fn report_error(e: &super::Error) {
let _ = writeln!(::std::io::stderr(), " {}", e);
}
}

/// The default target to pass to cargo, to workaround issue #11.
#[cfg(target_os="macos")]
pub fn default_target() -> &'static OsStr {
OsStr::new("x86_64-apple-darwin")
}

/// The default target to pass to cargo, to workaround issue #11.
#[cfg(not(target_os="macos"))]
pub fn default_target() -> &'static OsStr {
OsStr::new("x86_64-unknown-linux-gnu")
}

0 comments on commit 47563d6

Please sign in to comment.