Fix fnmatch caused oom
This commit is contained in:
@@ -43,6 +43,7 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Tree {
|
||||
}
|
||||
|
||||
let mut leading = true;
|
||||
let mut need_collapsing = false;
|
||||
|
||||
let mut builder = TreeBuilder::default();
|
||||
builder.start_internal(Token::Root, Range(1, Some(1)));
|
||||
@@ -55,6 +56,12 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Tree {
|
||||
let c = unsafe { *pattern };
|
||||
pattern = unsafe { pattern.offset(1) };
|
||||
|
||||
match (c == b'*', need_collapsing) {
|
||||
(true, true) => continue,
|
||||
(true, false) => need_collapsing = true,
|
||||
(false, _) => need_collapsing = false,
|
||||
}
|
||||
|
||||
let (token, range) = match c {
|
||||
b'\\' if flags & FNM_NOESCAPE == FNM_NOESCAPE => {
|
||||
let c = unsafe { *pattern };
|
||||
|
||||
@@ -29,3 +29,4 @@ Should fail:
|
||||
"[a!][a!]" doesn't match "ab"
|
||||
"hello[/+]world" doesn't match "hello/world"
|
||||
"hello world" doesn't match "HELLO WORLD"
|
||||
"********************a" doesn't match "xxxxxxxxxxxxxxxxxxxxb"
|
||||
|
||||
@@ -29,3 +29,4 @@ Should fail:
|
||||
"[a!][a!]" doesn't match "ab"
|
||||
"hello[/+]world" doesn't match "hello/world"
|
||||
"hello world" doesn't match "HELLO WORLD"
|
||||
"********************a" doesn't match "xxxxxxxxxxxxxxxxxxxxb"
|
||||
|
||||
@@ -44,4 +44,5 @@ int main(void) {
|
||||
test("[a!][a!]", "ab", 0);
|
||||
test("hello[/+]world", "hello/world", FNM_PATHNAME);
|
||||
test("hello world", "HELLO WORLD", 0);
|
||||
test("********************a", "xxxxxxxxxxxxxxxxxxxxb", 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user