Skip to content

Commit d65b41a

Browse files
committed
stty: fix: reject "+hex" in parse_saved_state
1 parent e6467b1 commit d65b41a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/uu/stty/src/stty.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,15 @@ fn parse_saved_state(arg: &str) -> Option<Vec<u32>> {
513513
// Validate all parts are non-empty valid hex
514514
let mut values = Vec::with_capacity(expected_parts);
515515
for (i, part) in parts.iter().enumerate() {
516+
// `from_str_radix` doesn't document its behavior for this case,
517+
// thus, we do this to guarantee stability
516518
if part.is_empty() {
517519
return None; // GNU rejects empty hex values
518520
}
521+
// TO-DO: avoid `from_str_radix`
522+
if part.as_bytes()[0] == b'+' {
523+
return None;
524+
};
519525
let val = u32::from_str_radix(part, 16).ok()?;
520526

521527
// Control characters (indices 4+) must fit in u8
@@ -997,7 +1003,7 @@ fn apply_char_mapping(termios: &mut Termios, mapping: &(S, u8)) {
9971003
///
9981004
/// The state array contains:
9991005
/// - `state[0]`: input flags
1000-
/// - `state[1]`: output flags
1006+
/// - `state[1]`: output flags
10011007
/// - `state[2]`: control flags
10021008
/// - `state[3]`: local flags
10031009
/// - `state[4..]`: control characters (optional)

0 commit comments

Comments
 (0)