Repository navigation
stat: reject a % directive with flags or a precision #15352
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
Changes from 5 commits
e57dc48
e220bf3
b97d276
a16f5dc
257043d
89cdef7
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 |
|---|---|---|
|
|
@@ -804,7 +804,7 @@ impl Stater { | |
| j += offset; | ||
|
|
||
| // Reject directives like `%<NUMBER>` by checking if width has been parsed. | ||
| if j >= bound || chars[j] == '%' { | ||
| if j >= bound { | ||
| let end = j.min(bound - 1); | ||
| let invalid_directive: String = chars[old..=end].iter().collect(); | ||
| return Err(DirectiveError::new( | ||
|
|
@@ -834,6 +834,18 @@ impl Stater { | |
| check_bound(format_str, bound, old, j)?; | ||
| } | ||
|
|
||
| // A `%` after flags, a width or a precision (`%0%`, `%-%`, `%.3%`) is | ||
| // not the `%%` escape; GNU rejects it as an invalid directive. | ||
| if chars[j] == '%' { | ||
|
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. the width branch above already does the same
Contributor
Author
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. Yes, the width branch now only handles the end of the format and leaves the |
||
| let invalid_directive: String = chars[old..=j].iter().collect(); | ||
| return Err(DirectiveError::new( | ||
| format_str, | ||
| &invalid_directive, | ||
| old, | ||
| j + 1, | ||
| )); | ||
| } | ||
|
|
||
| *i = j; | ||
|
|
||
| // Check for multi-character specifiers (e.g., `%Hd`, `%Lr`) | ||
|
|
||
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.
now that the
%check moved below, this block does the same as thecheck_boundon the next line, could be removed, no?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.
Right, removed it: check_bound on the next line reports the same directive when the width ends the format.