From e5b6f63305c4fa23ef5837309a8a4e7e911576ba Mon Sep 17 00:00:00 2001 From: papparapa <37232476+papparapa@users.noreply.github.com> Date: Sun, 12 Mar 2023 19:07:59 +0900 Subject: [PATCH] parser: fix index out of bounds error (#4484) + revert 1bc9980 to use files in workspace --- fuzz/Cargo.toml | 4 ++-- src/uucore/src/lib/parser/parse_glob.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 89c6bc4ef..c8565d691 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -11,10 +11,10 @@ cargo-fuzz = true libfuzzer-sys = "0.4" [dependencies.uucore] -uucore = { workspace = true } +path = "../src/uucore/" [dependencies.uu_date] -uu_date = { workspace = true } +path = "../src/uu/date/" # Prevent this from interfering with workspaces [workspace] diff --git a/src/uucore/src/lib/parser/parse_glob.rs b/src/uucore/src/lib/parser/parse_glob.rs index 8605f7450..a321d470b 100644 --- a/src/uucore/src/lib/parser/parse_glob.rs +++ b/src/uucore/src/lib/parser/parse_glob.rs @@ -10,8 +10,9 @@ fn fix_negation(glob: &str) -> String { let mut chars = glob.chars().collect::>(); let mut i = 0; - while i < chars.len() { - if chars[i] == '[' && i + 4 <= glob.len() && chars[i + 1] == '^' { + // Add 3 to prevent out of bounds in loop + while i + 3 < chars.len() { + if chars[i] == '[' && chars[i + 1] == '^' { match chars[i + 3..].iter().position(|x| *x == ']') { None => (), Some(j) => { @@ -105,5 +106,8 @@ mod tests { assert_eq!(fix_negation("[^]"), "[^]"); assert_eq!(fix_negation("[^"), "[^"); assert_eq!(fix_negation("[][^]"), "[][^]"); + + // Issue #4479 + assert_eq!(fix_negation("ààà[^"), "ààà[^"); } }