From 9d610374d7016f21e1271b8d78b2a89f8746b243 Mon Sep 17 00:00:00 2001 From: Guillaume Dallenne Date: Thu, 10 Nov 2022 10:57:07 +0100 Subject: [PATCH 1/5] Rename run to __libfuzzer_sys_run This reduces chances of function collision. When using the `fuzz_target` macro, calling `run` inside the block will call the `run` function declared inside the macro definition instead of calling the `run` function defined in the module using `fuzz_target`. Using the `run` function of the macro is probably not the intended goal because it leads to a recursive call. Renaming makes it less likely to call `__libfuzzer_sys_run` by accident. --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ce1eb98..376feb9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -221,7 +221,7 @@ macro_rules! fuzz_target { return 0; } - run(bytes); + __libfuzzer_sys_run(bytes); 0 } @@ -234,11 +234,11 @@ macro_rules! fuzz_target { // panics in separate fuzzers can accidentally appear the same // because each fuzzer will have a function called // `rust_fuzzer_test_input`. By using a normal Rust function here - // it's named something like `the_fuzzer_name::_::run` which should + // it's named something like `the_fuzzer_name::_::__libfuzzer_sys_run` which should // ideally help prevent oss-fuzz from deduplicate fuzz bugs across // distinct targets accidentally. #[inline(never)] - fn run($bytes: &[u8]) { + fn __libfuzzer_sys_run($bytes: &[u8]) { $body } }; @@ -294,13 +294,13 @@ macro_rules! fuzz_target { Err(_) => return -1, }; - let result = ::libfuzzer_sys::Corpus::from(run(data)); + let result = ::libfuzzer_sys::Corpus::from(__libfuzzer_sys_run(data)); result.to_libfuzzer_code() } // See above for why this is split to a separate function. #[inline(never)] - fn run($data: $dty) -> $rty { + fn __libfuzzer_sys_run($data: $dty) -> $rty { $body } }; From 7a7f78d2ff8b0e9813da7e9991919ed198a18e49 Mon Sep 17 00:00:00 2001 From: Addison Crump Date: Tue, 3 Jan 2023 21:44:19 +0100 Subject: [PATCH 2/5] fix some minor build.rs issues --- build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index bf6c12f..9d1a76a 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,11 @@ fn main() { + println!("cargo:rerun-if-env-changed=CUSTOM_LIBFUZZER_PATH"); if let Ok(custom) = ::std::env::var("CUSTOM_LIBFUZZER_PATH") { let custom_lib_path = ::std::path::PathBuf::from(&custom); let custom_lib_dir = custom_lib_path.parent().unwrap().to_string_lossy(); let custom_lib_name = custom_lib_path.file_stem().unwrap().to_string_lossy(); - let custom_lib_name = custom_lib_name.trim_start_matches("lib"); + let custom_lib_name = custom_lib_name.strip_prefix("lib").unwrap_or(custom_lib_name.as_ref()); println!("cargo:rustc-link-search=native={}", custom_lib_dir); println!("cargo:rustc-link-lib=static={}", custom_lib_name); From f47576d2afb5549cb9343204391d490eceeaad6f Mon Sep 17 00:00:00 2001 From: Addison Crump Date: Tue, 3 Jan 2023 21:55:41 +0100 Subject: [PATCH 3/5] fmt --- build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 9d1a76a..6403f2f 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,9 @@ fn main() { let custom_lib_dir = custom_lib_path.parent().unwrap().to_string_lossy(); let custom_lib_name = custom_lib_path.file_stem().unwrap().to_string_lossy(); - let custom_lib_name = custom_lib_name.strip_prefix("lib").unwrap_or(custom_lib_name.as_ref()); + let custom_lib_name = custom_lib_name + .strip_prefix("lib") + .unwrap_or(custom_lib_name.as_ref()); println!("cargo:rustc-link-search=native={}", custom_lib_dir); println!("cargo:rustc-link-lib=static={}", custom_lib_name); From 663c0b6c212e9cb1000b182aef260406115402ae Mon Sep 17 00:00:00 2001 From: Addison Crump Date: Wed, 25 Jan 2023 17:05:07 +0100 Subject: [PATCH 4/5] rerun if the targeted library is also changed, not just if the path does --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index 6403f2f..ab1bbc5 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,8 @@ fn main() { println!("cargo:rerun-if-env-changed=CUSTOM_LIBFUZZER_PATH"); if let Ok(custom) = ::std::env::var("CUSTOM_LIBFUZZER_PATH") { + println!("cargo:rerun-if-changed={custom}"); + let custom_lib_path = ::std::path::PathBuf::from(&custom); let custom_lib_dir = custom_lib_path.parent().unwrap().to_string_lossy(); From e07c487220402f5bec2151de2856a7caff0639c6 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 26 Jan 2023 09:39:20 -0800 Subject: [PATCH 5/5] Bump to version 0.4.6 --- CHANGELOG.md | 12 ++++++++++++ Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a924906..0fba42c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,18 @@ Released YYYY-MM-DD. -------------------------------------------------------------------------------- +## 0.4.6 + +Released 2023-01-26. + +### Fixed + +* Fixed a potential name conflict in functions generated by the `fuzz_target!` + macro. +* Fixed potential stale builds when updating custom libfuzzers to link against. + +-------------------------------------------------------------------------------- + ## 0.4.5 Released 2022-10-18. diff --git a/Cargo.toml b/Cargo.toml index bc5982d..1552302 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT/Apache-2.0/NCSA" name = "libfuzzer-sys" readme = "./README.md" repository = "https://github.com/rust-fuzz/libfuzzer" -version = "0.4.5" +version = "0.4.6" [dependencies] arbitrary = "1"