From adbd2cadffd115ef49d52cfdf957d1c385a7733d Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Mon, 6 Jun 2022 21:15:44 -0400 Subject: [PATCH 1/5] tests: Avoid using globs as regexes --- bindgen-tests/tests/headers/empty-union.hpp | 2 +- bindgen-tests/tests/headers/forward_declared_opaque.h | 4 ++-- bindgen-tests/tests/headers/ord-enum.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen-tests/tests/headers/empty-union.hpp b/bindgen-tests/tests/headers/empty-union.hpp index 3b067e39da..113a95ee30 100644 --- a/bindgen-tests/tests/headers/empty-union.hpp +++ b/bindgen-tests/tests/headers/empty-union.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type "*" +// bindgen-flags: --opaque-type ".*" template class a { union {}; diff --git a/bindgen-tests/tests/headers/forward_declared_opaque.h b/bindgen-tests/tests/headers/forward_declared_opaque.h index 1b58edb9a8..69a12cc7e2 100644 --- a/bindgen-tests/tests/headers/forward_declared_opaque.h +++ b/bindgen-tests/tests/headers/forward_declared_opaque.h @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type "*" +// bindgen-flags: --opaque-type ".*" union a; -struct b; \ No newline at end of file +struct b; diff --git a/bindgen-tests/tests/headers/ord-enum.h b/bindgen-tests/tests/headers/ord-enum.h index 364f711efa..b14e77c2f8 100644 --- a/bindgen-tests/tests/headers/ord-enum.h +++ b/bindgen-tests/tests/headers/ord-enum.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rustified-enum * --with-derive-ord +// bindgen-flags: --rustified-enum ".*" --with-derive-ord enum A { A0 = 0, @@ -12,4 +12,4 @@ enum B { B1 = B0 + 3, B2 = B0 + 2, B3 = B0 - 2, -}; \ No newline at end of file +}; From 189c6f304a565e3c23e49c79b30ab978322ac079 Mon Sep 17 00:00:00 2001 From: Adam Gausmann Date: Tue, 24 Mar 2020 22:00:41 -0500 Subject: [PATCH 2/5] Sanitize regex set input to properly handle alternation --- bindgen/regex_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 9262c4eeda..f75ba8c44f 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -53,7 +53,7 @@ impl RegexSet { /// Must be called before calling `matches()`, or it will always return /// false. pub fn build(&mut self, record_matches: bool) { - let items = self.items.iter().map(|item| format!("^{}$", item)); + let items = self.items.iter().map(|item| format!("^({})$", item)); self.record_matches = record_matches; self.set = match RxSet::new(items) { Ok(x) => Some(x), From 98551a64097e965facc93a55b9b38eb635252eae Mon Sep 17 00:00:00 2001 From: Adam Gausmann Date: Thu, 14 May 2020 08:45:36 -0500 Subject: [PATCH 3/5] Add test case for alternates/anchors interaction --- .../tests/whitelist-alternates.rs | 39 +++++++++++++++++++ .../tests/headers/whitelist-alternates.h | 8 ++++ 2 files changed, 47 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/whitelist-alternates.rs create mode 100644 bindgen-tests/tests/headers/whitelist-alternates.h diff --git a/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs b/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs new file mode 100644 index 0000000000..77d963d81e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs @@ -0,0 +1,39 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct WhitelistedType {} +#[test] +fn bindgen_test_layout_WhitelistedType() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(WhitelistedType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(WhitelistedType)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct AllowType {} +#[test] +fn bindgen_test_layout_AllowType() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(AllowType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AllowType)) + ); +} diff --git a/bindgen-tests/tests/headers/whitelist-alternates.h b/bindgen-tests/tests/headers/whitelist-alternates.h new file mode 100644 index 0000000000..7aa3bf8711 --- /dev/null +++ b/bindgen-tests/tests/headers/whitelist-alternates.h @@ -0,0 +1,8 @@ +// bindgen-flags: --whitelist-type 'Whitelisted.*|Allow.*' +// Test for changes introduced in #1756 + +struct WhitelistedType {}; +struct AllowType {}; +// this would have been accepted because the start anchor +// wouldn't be applied to the second alternative: +struct NoAllowType {}; From fb68a70b8b62ac9e943d266d7e09aa6fe4c347c1 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 13 Oct 2022 10:15:58 -0500 Subject: [PATCH 4/5] emit warning if wildcard pattern is used --- bindgen/regex_set.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index f75ba8c44f..9f1e2251cd 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -26,7 +26,11 @@ impl RegexSet { where S: AsRef, { - self.items.push(string.as_ref().to_owned()); + let string = string.as_ref().to_owned(); + if string == "*" { + warn!("using wildcard patterns (`*`) is no longer considered valid. Use `.*` instead"); + } + self.items.push(string); self.matched.push(Cell::new(false)); self.set = None; } From 94167f3024f94e7ace7d918958ef48a568f1ee9d Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 13 Oct 2022 10:18:03 -0500 Subject: [PATCH 5/5] update changelog and bump versions --- CHANGELOG.md | 3 +++ Cargo.lock | 4 ++-- bindgen-cli/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9c5aca4a4..87a74acd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -151,6 +151,9 @@ ## Changed + * Regex inputs are sanitized so alternation (`a|b`) is handled correctly but + wildcard patterns (`*`) are now considered invalid. + ## Removed ## Fixed diff --git a/Cargo.lock b/Cargo.lock index 765f391fd2..d656f9dd32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,7 +48,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bindgen" -version = "0.61.0" +version = "0.62.0" dependencies = [ "bitflags", "cexpr", @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.61.0" +version = "0.62.0" dependencies = [ "bindgen", "clap 3.2.12", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index b4feb6d9ce..7bff8f46b8 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.61.0" +version = "0.62.0" edition = "2018" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml rust-version = "1.57.0" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 5a8e96be8c..13e5f44590 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.61.0" +version = "0.62.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml