Repository navigation
mode: reject empty clauses and bare octal inside comma lists - #15378
eylulseyit wants to merge 1 commit into
Conversation
Merging this PR will not alter performance1 warning, 1 note
Comparing Footnotes
|
ec018ab to
f6fc49f
Compare
|
Hi, I looked into the CodSpeed report a bit. As far as I can tell, the dd memory regression isn't coming from the mode changes (dd doesn't use that code). It seems to come from the two new messages in uucore's en-US.ftl. |
f6fc49f to
cf8b224
Compare
|
I deleted the two error messages I had added to the locale files. Errors now just say "invalid mode", like GNU. The message is hardcoded, like the existing invalid mode (...) in mode.rs. The dd, mv, and hostname regressions are gone now. Any new message in uucore will hit the same limit in dd, so it might be worth keeping in mind. |
cf8b224 to
0e998c4
Compare
| }; | ||
| let mut offset = 0; | ||
| for clause in cmode.split(',') { | ||
| if let Err(error) = mode::check_clause(cmode, clause) { |
There was a problem hiding this comment.
this is the same split/offset loop as in calculate_new_mode, could they share it?
There was a problem hiding this comment.
Yes. I deleted check_mode because calculate_new_mode already does the same job. Since #15166 was merged, calculate_new_mode is called once on main before any file is read, so an invalid mode is rejected before the files are touched.
| assert_eq!(parse("-4", false, 0).unwrap(), 0); | ||
| // But if we first set a mode, then remove bits | ||
| assert_eq!(parse("644,-4", false, 0).unwrap(), 0o640); | ||
| assert_eq!(parse("=644,-4", false, 0).unwrap(), 0o640); |
There was a problem hiding this comment.
for 644, the error says "octal mode 644 must be the whole mode", which is confusing. Could we check for empty clauses first?
41f4f04 to
f09e03d
Compare
|
GNU testsuite comparison: |
f09e03d to
4eb297a
Compare
GNU rejects comma-separated mode strings containing empty clauses (e.g.,
u+x,,'') or bare octal values mixed with other clauses (e.g.,644,u+x). Previously, these were accepted, leading to incorrect permissions, such asmkdir -m ''creating a 0777 directory orinstall -m '' a bleaving a 000 file.This introduces a check_clause validation helper in uucore::mode, called from both parse_chmod (used by mkdir, install, mkfifo, and mknod) and from chmod. Octals with an explicit operator remain supported in lists (e.g.
+644,u+x,u+x,=600) to match GNU behavior. Existing unit tests asserting the prior behavior have been updated to expect errors or use valid forms like=644,....The errors are a plain "invalid mode", like GNU. The message is hardcoded like the existing
invalid mode (...)inparse_symbolic, because adding a translated message to uucore makes dd's locale table grow (see the CodSpeed comment below).The dedicated loop in
chmodis retained for now to keep this change focused; consolidating the parsing paths can follow in a separate PR. Whitespace trimming around clauses is unchanged, and #12709 is out of scope.Closes #14421