You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sed - unknown POSIX class names like [[:foo:]] or [[:word:]] are accepted instead of rejected #646
GNU sed accepts only the POSIX character class names (alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit) and stops with Invalid character class name and exit status 1 for anything else. uutils sed copies the name
through to the Rust regex engine, which silently accepts its own extra names ([[:word:]], [[:ascii:]]) and treats a misspelt name such as [[:foo:]] in some other way, with exit
status 0.
$ printf'a\n'| /usr/bin/sed 's/[[:foo:]]/X/'
/usr/bin/sed: -e expression #1, char 14: Invalid character class name# Exit code: 1
$ printf'a_\n'| /usr/bin/sed 's/[[:word:]]/X/'
/usr/bin/sed: -e expression #1, char 15: Invalid character class name# Exit code: 1
Root cause
parse_character_class in src/sed/delimited_parser.rs:283-312 reads the name between [: and :] into inner and copies it to the output without checking it:
if c == marker {
line.advance();if !line.eol() && line.current() == ']'{
line.advance();
result.extend_from_slice(&inner);
result.push(marker asu8);
result.push(b']');
terminated = true;break;}
Test
#[rstest]#[case::misspelt("s/[[:foo:]]/X/")]#[case::rust_only_word("s/[[:word:]]/X/")]#[case::rust_only_ascii("s/[[:ascii:]]/X/")]fntest_invalid_character_class_name(#[case]script:&str){new_ucmd!().arg(script).pipe_in("a\n").fails().code_is(1).stderr_contains("Invalid character class name");}#[test]fntest_valid_character_class_names_still_work(){new_ucmd!().arg("s/[[:digit:][:upper:]]/X/g").pipe_in("a1B\n").succeeds().stdout_is("aXX\n");}
Reported by Anthropic's OSS Scanner (ANT-2026-B5YF79Y6).
Activity
majidninja commentedon Nov 16, 2026
Hi, I'd like to take this one. I've got a fix ready and will open a PR soon.