mirror of
https://github.com/openharmony/third_party_rust_bindgen.git
synced 2026-07-18 17:34:33 -04:00
Sanitize RegexSet input so alternation is properly handled (#1756)
* tests: Avoid using globs as regexes * Sanitize regex set input to properly handle alternation * Add test case for alternates/anchors interaction * emit warning if wildcard pattern is used * update changelog and bump versions Co-authored-by: Darren Kulp <darren@kulp.ch> Co-authored-by: Christian Poveda <christian.poveda@ferrous-systems.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Generated
+2
-2
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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::<WhitelistedType>(),
|
||||
0usize,
|
||||
concat!("Size of: ", stringify!(WhitelistedType))
|
||||
);
|
||||
assert_eq!(
|
||||
::std::mem::align_of::<WhitelistedType>(),
|
||||
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::<AllowType>(),
|
||||
0usize,
|
||||
concat!("Size of: ", stringify!(AllowType))
|
||||
);
|
||||
assert_eq!(
|
||||
::std::mem::align_of::<AllowType>(),
|
||||
1usize,
|
||||
concat!("Alignment of ", stringify!(AllowType))
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// bindgen-flags: --opaque-type "*"
|
||||
// bindgen-flags: --opaque-type ".*"
|
||||
|
||||
template <int> class a {
|
||||
union {};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// bindgen-flags: --opaque-type "*"
|
||||
// bindgen-flags: --opaque-type ".*"
|
||||
|
||||
union a;
|
||||
struct b;
|
||||
struct b;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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 {};
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -26,7 +26,11 @@ impl RegexSet {
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -53,7 +57,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),
|
||||
|
||||
Reference in New Issue
Block a user