Repository navigation
Conversation
|
Mixed clauses still get through. On the PR head (e316716), these modes return rc 0 for both
The check looks at the whole string, so a numeric clause next to a symbolic one passes. Checking each clause would fix it: a numeric mode is valid only as the single clause. #15378 does this per clause in |
|
@fixfon Thanks for investigating, but please compare against GNU coreutils 9.12 or GNU coreutils master branch. |
e316716 to
0433c4f
Compare
|
@xtqqczze Re-checked against GNU coreutils 9.12 (built locally on Linux, same results as 9.7) with the current head (0433c4f). GNU rejects all of these with
The purely numeric lists ( So this matches what @sylvestre pointed out. Rejecting a numeric clause in |
7ea68c0 to
04a4d3c
Compare
|
Moved the rule into |
|
GNU testsuite comparison: |
Merging this PR will degrade performance by 3.83%2 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
4c20081 to
608b658
Compare
d8b9155 to
b514ba1
Compare
GNU reads a comma-separated mode as a list of symbolic clauses, so a clause that is plain octal makes the whole mode invalid. Checking the rule in uucore::mode::parse_chmod covers mkdir, mkfifo and mknod in one place; chmod keeps its own clause loop, so it needs the same guard.
Remove the redundant numeric-comma precheck so parse_symbolic produces the standard invalid-mode diagnostic, and add mkdir/mkfifo/mknod coverage for the rejection path.
A numeric clause in a list may carry a run of operators before the number, as in `=+755`, `++755` or `-+755`. `parse_numeric` now consumes the whole run, and an `=` inside it resets the ordinary permission bits while keeping a directory's setuid/setgid bits: `chmod =+755` on a 6755 directory leaves it at 6755, as GNU does, instead of dropping to 755. Whitespace between the operators still keeps the clause symbolic, so `u+x,+ 755` stays an invalid mode. The tests also check that rejected modes leave the target untouched and that mkfifo applies an accepted symbolic mode.
Clippy rejects the loop/let-else form as while_let_loop.
The rule is documented on is_numeric_clause, so the copies in chmod and parse_chmod only repeat it.
b514ba1 to
3b64036
Compare
mkdir -mandmkfifo --modeaccepted a numeric mode with a comma such as1,2and silently applied only the last clause:mkdir -m 1,2 dcreateddwith mode0002and exited 0. GNU rejects it:GNU reads a comma-separated mode as a list of symbolic clauses, so a bare octal is only valid as the whole mode string. A numeric clause with an explicit
+,-or=operator stays valid inside a list, as in GNU's own=7777,-5022test case.The rule now lives in
uucore::mode::parse_chmod(is_numeric_clause), so it covers every caller at once:mkdir,mkfifo,mknodandchmod, which keeps its own clause loop and got the same check.755,u+w,u+w,755,a=rx,700,u=r,2,1,u=wand+1,2are all rejected now, and755,u+wno longer leaves a mode behind. Comma-separated symbolic modes such asu=rwx,g=rx,o=still work.Two behaviours that GNU has and we did not are fixed along the way, because the old code called
parse_numericon the first operator only:=+755,++755or-+755, is accepted, and=still keeps a directory's setuid/setgid bits like GNU does;parse_numericno longer accepts whitespace between the operators and the digits, sou+x,+ 755is rejected like GNU.Tests:
tests/by-util/test_chmod.rs::test_numeric_mode_must_be_the_whole_modetests/by-util/test_mkdir.rs::diagnostics::test_comma_separated_mode_is_rejectedtests/by-util/test_mkfifo.rs::test_comma_separated_numeric_mode_is_rejectedand::test_comma_separated_symbolic_mode_is_acceptedtests/by-util/test_mknod.rs::test_mknod_comma_separated_numeric_mode_is_rejectedsrc/uucore/src/lib/features/mode.rs::test_numeric_mode_must_stand_aloneand::test_parse_considering_dirCloses #16001