/// Add new target for libfuzzer using `cargo fuzz add`
Add new target for libfuzzer using `cargo fuzz add`
Add new target for libfuzzer using ` cargo fuzz add `
fn write_libfuzzer_target(fuzzer_dir: &PathBuf, target: Targets) -> Result<(), Error> {
    use std::io::Write;
    let fuzz_dir = fuzzer_dir.join("fuzz");
    let template_path = fuzzer_dir.join(target.template());
    let template = fs::read_to_string(&template_path).context(format!(
        "error reading template file {}",
        template_path.display()
    ))?;
    // use `cargo fuzz add` to add new bin inside Cargo.toml
    // and create fuzz_targets dir
    // and create target.rs
    let _ = Command::new("cargo") // "+nightly",
        .args(&["fuzz", "add", &target.name()])
        .current_dir(&fuzzer_dir)
        .spawn()
        .context(format!("error adding {}", target.name()))?
        .wait()
        .context(format!("error while adding {}", target.name()));
    let target_dir = fuzz_dir.join("fuzz_targets");
    let path = target_dir.join(&format!("{}.rs", target.name()));
    let mut file = fs::OpenOptions::new()
        .write(true)
        .create(true)
        .truncate(true)
        .open(&path)
        .context(format!(
            "write_libfuzzer_target error writing fuzz target binary {}",
            path.display()
        ))?;
    let source = template.replace("###TARGET###", &target.name());
    file.write_all(source.as_bytes())?;
    Ok(())
}
fn write_libfuzzer_target ( fuzzer_dir : & PathBuf , target : Targets ) -> Result < ( ) , Error > { use std :: io :: Write ; let fuzz_dir = fuzzer_dir . join ( " " ) ; let template_path = fuzzer_dir . join ( target . template ( ) ) ; let template = fs :: read_to_string ( & template_path ) . context ( format ! ( " " template_path display ( ) ) ) ? ; // use `cargo fuzz add` to add new bin inside Cargo.toml // and create fuzz_targets dir // and create target.rs let _ = Command :: new ( " " ) // "+nightly", . args ( & [ " " , " " , & target . name ( ) ] ) . current_dir ( & fuzzer_dir ) . spawn ( ) . context ( format ! ( " " target name ( ) ) ) ? . wait ( ) . context ( format ! ( " " target name ( ) ) ) ; let target_dir = fuzz_dir . join ( " " ) ; let path = target_dir . join ( & format ! ( " " target name ( ) ) ) ; let mut file = fs :: OpenOptions :: new ( ) . write ( true ) . create ( true ) . truncate ( true ) . open ( & path ) . context ( format ! ( " " path display ( ) ) ) ? ; let source = template . replace ( " " , & target . name ( ) ) ; file . write_all ( source . as_bytes ( ) ) ? ; Ok ( ( ) ) }
Add new target for libfuzzer using `cargo fuzz add`
Add new target for libfuzzer using ` cargo fuzz add `
fuzzer_dir
&PathBuf
target
Targets