Skip to content

Commit 24c0d86

Browse files
committed
sh: getopts fails with invalid optstring
1 parent 8209d9e commit 24c0d86

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sh/src/builtin/getopts.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ enum ParseResult<'s> {
2727

2828
impl<'s> OptsParser<'s> {
2929
fn new(optstring: &'s str) -> Result<Self, String> {
30-
// TODO: check that optstring is valid
30+
if !optstring
31+
.chars()
32+
.all(|c| c.is_ascii_alphabetic() || c == ':')
33+
{
34+
return Err("getopts: invalid option string".into());
35+
}
3136
Ok(Self { optstring })
3237
}
3338

0 commit comments

Comments
 (0)