-
Notifications
You must be signed in to change notification settings - Fork 109
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
Add transitional message #348
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,6 @@ | ||
[package] | ||
name = "afl" | ||
version = "0.13.1" | ||
readme = "README.md" | ||
license = "Apache-2.0" | ||
authors = ["Keegan McAllister <[email protected]>", | ||
"Corey Farwell <[email protected]>"] | ||
description = "Fuzzing Rust code with american-fuzzy-lop" | ||
repository = "https://github.com/rust-fuzz/afl.rs" | ||
homepage = "https://github.com/rust-fuzz/afl.rs" | ||
edition = "2021" | ||
|
||
[build-dependencies] | ||
fs_extra = "1.3" | ||
home = "0.5" | ||
rustc_version = "0.4" | ||
tempfile = "3.6" | ||
xdg = "2.4" | ||
|
||
[dependencies] | ||
clap = { version = "4.3", features = ["cargo"] } | ||
lazy_static = { version = "1.4.0", optional = true } | ||
libc = "0.2.147" | ||
rustc_version = "0.4" | ||
xdg = "2.4" | ||
|
||
[dev-dependencies] | ||
arbitrary = { version = "1", features = ["derive"] } | ||
assert_cmd = "2.0" | ||
tempfile = "3.6" | ||
|
||
[features] | ||
reset_lazy_static = ["lazy_static"] | ||
no_cfg_fuzzing = [] | ||
[workspace] | ||
members = [ | ||
"afl", | ||
"cargo-afl", | ||
] | ||
resolver = "2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
name = "afl" | ||
version = "0.13.1" | ||
readme = "../README.md" | ||
license = "Apache-2.0" | ||
authors = ["Keegan McAllister <[email protected]>", | ||
"Corey Farwell <[email protected]>"] | ||
description = "Fuzzing Rust code with american-fuzzy-lop" | ||
repository = "https://github.com/rust-fuzz/afl.rs" | ||
homepage = "https://github.com/rust-fuzz/afl.rs" | ||
edition = "2021" | ||
|
||
[build-dependencies] | ||
fs_extra = "1.3" | ||
home = "0.5" | ||
libc = "0.2" | ||
rustc_version = "0.4" | ||
tempfile = "3.6" | ||
xdg = "2.4" | ||
|
||
[dependencies] | ||
clap = { version = "4.3", features = ["cargo"] } | ||
lazy_static = { version = "1.4", optional = true } | ||
libc = "0.2" | ||
rustc_version = "0.4" | ||
xdg = "2.4" | ||
|
||
[dev-dependencies] | ||
arbitrary = { version = "1", features = ["derive"] } | ||
assert_cmd = "2.0" | ||
tempfile = "3.6" | ||
|
||
[features] | ||
reset_lazy_static = ["lazy_static"] | ||
no_cfg_fuzzing = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ use std::env; | |
use std::path::{Path, PathBuf}; | ||
use std::process::Command; | ||
|
||
static AFL_SRC_PATH: &str = "AFLplusplus"; | ||
static AFL_SRC_PATH: &str = "../AFLplusplus"; | ||
|
||
// https://github.com/rust-fuzz/afl.rs/issues/148 | ||
#[cfg(target_os = "macos")] | ||
|
@@ -16,11 +16,25 @@ mod common; | |
fn main() { | ||
let installing = home::cargo_home() | ||
.map(|path| Path::new(env!("CARGO_MANIFEST_DIR")).starts_with(path)) | ||
.unwrap(); | ||
.unwrap() | ||
|| env::var("TESTING_INSTALL").is_ok(); | ||
|
||
let building_cargo_afl = env::var("CARGO_PKG_NAME") == Ok(String::from("cargo-afl")); | ||
|
||
let building_on_docs_rs = env::var("DOCS_RS").is_ok(); | ||
|
||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
|
||
if installing && !building_cargo_afl { | ||
println!("cargo:warning=You appear to be installing `cargo-afl` with:"); | ||
println!("cargo:warning= cargo install afl"); | ||
println!("cargo:warning=A future version of afl.rs will require you to use:"); | ||
println!("cargo:warning= cargo install cargo-afl"); | ||
println!("cargo:warning=You can use the new command now, if you like."); | ||
} | ||
|
||
// smoelius: Build AFLplusplus in a temporary directory when installing or when building on docs.rs. | ||
let work_dir = if installing || env::var("DOCS_RS").is_ok() { | ||
let work_dir = if installing || building_on_docs_rs { | ||
let tempdir = tempfile::tempdir_in(&out_dir).unwrap(); | ||
if Path::new(AFL_SRC_PATH).join(".git").is_dir() { | ||
let status = Command::new("git") | ||
|
@@ -44,12 +58,16 @@ fn main() { | |
PathBuf::from(AFL_SRC_PATH) | ||
}; | ||
|
||
let base = if env::var("DOCS_RS").is_ok() { | ||
let base = if building_on_docs_rs { | ||
Some(PathBuf::from(out_dir)) | ||
} else { | ||
None | ||
}; | ||
|
||
// smoelius: Lock `work_dir` until the build script exits. | ||
#[cfg(unix)] | ||
let _file = sys::lock_path(&work_dir).unwrap(); | ||
Comment on lines
+71
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just making sure I understand: this doesn't require an associated I believe that should be fine, but it's not super well defined by POSIX AFAICT. Just something to be aware of should it cause unusual behavior on non-Linux builds in the future 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's correct.
I'm curious as to what makes you say that (not saying you're wrong). I'm reading this: https://man7.org/linux/man-pages/man2/flock.2.html
Is file descriptor closure not well defined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I thought POSIX was ambiguous on whether process termination is actually required to close all FDs, but it looks like it's unambiguous:
(From https://pubs.opengroup.org/onlinepubs/007904875/functions/exit.html) There's some subtlety around child processes that inherit the open FD, but I don't think that case matters here. So this is safe to ignore 🙂 |
||
|
||
build_afl(&work_dir, base.as_deref()); | ||
build_afl_llvm_runtime(&work_dir, base.as_deref()); | ||
} | ||
|
@@ -85,3 +103,33 @@ fn build_afl_llvm_runtime(work_dir: &Path, base: Option<&Path>) { | |
.expect("could not run 'ar'"); | ||
assert!(status.success()); | ||
} | ||
|
||
#[cfg(unix)] | ||
mod sys { | ||
use std::fs::File; | ||
use std::io::{Error, Result}; | ||
use std::os::unix::io::AsRawFd; | ||
use std::path::Path; | ||
|
||
pub fn lock_path(path: &Path) -> Result<File> { | ||
let file = File::open(path)?; | ||
lock_exclusive(&file)?; | ||
Ok(file) | ||
} | ||
|
||
// smoelius: `lock_exclusive` and `flock` were copied from: | ||
// https://github.com/rust-lang/cargo/blob/ae91d4ed41da98bdfa16041dbc6cd30287920120/src/cargo/util/flock.rs | ||
|
||
fn lock_exclusive(file: &File) -> Result<()> { | ||
flock(file, libc::LOCK_EX) | ||
} | ||
|
||
fn flock(file: &File, flag: libc::c_int) -> Result<()> { | ||
let ret = unsafe { libc::flock(file.as_raw_fd(), flag) }; | ||
if ret < 0 { | ||
Err(Error::last_os_error()) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "cargo-afl" | ||
version = "0.13.1" | ||
readme = "../README.md" | ||
license = "Apache-2.0" | ||
authors = ["Keegan McAllister <[email protected]>", | ||
"Corey Farwell <[email protected]>", | ||
"Samuel Moelius <[email protected]>"] | ||
description = "Fuzzing Rust code with american-fuzzy-lop" | ||
repository = "https://github.com/rust-fuzz/afl.rs" | ||
homepage = "https://github.com/rust-fuzz/afl.rs" | ||
edition = "2021" | ||
|
||
build = "../afl/build.rs" | ||
|
||
[[bin]] | ||
name = "cargo-afl" | ||
path = "../afl/src/bin/cargo-afl.rs" | ||
|
||
[build-dependencies] | ||
fs_extra = "1.3" | ||
home = "0.5" | ||
libc = "0.2" | ||
rustc_version = "0.4" | ||
tempfile = "3.6" | ||
xdg = "2.4" | ||
|
||
[dependencies] | ||
clap = { version = "4.3", features = ["cargo"] } | ||
libc = "0.2" | ||
rustc_version = "0.4" | ||
xdg = "2.4" | ||
|
||
[dev-dependencies] | ||
assert_cmd = "2.0" | ||
predicates = "3.0" | ||
tempfile = "3.6" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to also suggest
cargo uninstall afl
, or is the lattercargo-afl
going to effectively clobber the install anyways?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than suggest to uninstall, I propose the following. Change the first line to:
And add the following line at the end:
So the revised message would look like:
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!