Skip to content

Commit

Permalink
ls: Clamp overflowing size in --width to a max value
Browse files Browse the repository at this point in the history
  • Loading branch information
Skryptonyte committed Jul 12, 2023
1 parent a1b4d25 commit 4ff1236
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,24 @@ impl Config {
// Read number as octal
match u16::from_str_radix(x, 8) {
Ok(v) => v,
Err(_) => return Err(LsError::InvalidLineWidth(x.into()).into()),
Err(err) => {
// If number parsed is too large, clamp to maximum value
match err.to_string() == "number too large to fit in target type" {
true => u16::MAX,
_ => return Err(LsError::InvalidLineWidth(x.into()).into()),
}
}
}
} else {
match x.parse::<u16>() {
Ok(u) => u,
Err(_) => return Err(LsError::InvalidLineWidth(x.into()).into()),
Err(err) => {
// If number parsed is too large, clamp to maximum value
match err.to_string() == "number too large to fit in target type" {
true => u16::MAX,
_ => return Err(LsError::InvalidLineWidth(x.into()).into()),
}
}
}
}
}
Expand Down

0 comments on commit 4ff1236

Please sign in to comment.