-
-
Notifications
You must be signed in to change notification settings - Fork 2k
nl: reject line number width above INT_MAX instead of aborting #13880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -376,7 +376,10 @@ pub fn uu_app() -> Command { | |||||
| .long(options::NUMBER_WIDTH) | ||||||
| .help(translate!("nl-help-number-width")) | ||||||
| .value_name("NUMBER") | ||||||
| .value_parser(clap::value_parser!(usize)), | ||||||
| // Bound the width to a C int like GNU. This rejects a huge width | ||||||
| // up front instead of letting a later `" ".repeat(width + 1)` | ||||||
| // abort with a capacity overflow (#13347). | ||||||
| .value_parser(clap::value_parser!(u64).range(..=i32::MAX as u64)), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't make stderr 100% same with GNU too. |
||||||
| ) | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,6 +187,17 @@ fn test_number_width_zero() { | |
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_number_width_above_int_max_is_rejected() { | ||
| // A field width above i32::MAX is rejected up front by clap, matching GNU's | ||
| // C-int bound, instead of aborting with a capacity overflow (#13347). | ||
| new_ucmd!() | ||
| .args(&["-w", "2147483648"]) | ||
| .pipe_in("x\n") | ||
| .fails() | ||
| .stderr_contains("is not in 0..=2147483647"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would drop .stderr_contains and kep fails only since it is clap's message instead of GNU's one. |
||
| } | ||
|
|
||
| #[test] | ||
| fn test_invalid_number_width() { | ||
| for arg in ["-winvalid", "--number-width=invalid"] { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If test is added already, the comment is unnecessary.