Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn parse_numeric(fperm: u32, mut mode: &str, considering_dir: bool) -> Resul
u32::from_str_radix(mode, 8).map_err(|e| e.to_string())?
};
if change > 0o7777 {
Err(format!("mode is too large ({change} > 7777"))
Err(format!("mode is too large ({change:o} > 7777)"))
} else {
Ok(match op {
Some('+') => fperm | change,
Expand Down
27 changes: 27 additions & 0 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,33 @@ fn test_chmod_error_permissions() {
);
}

#[test]
fn test_chmod_permissions_too_large() {
let scenario = TestScenario::new(util_name!());
let at = &scenario.fixtures;

at.touch("file");

scenario
.ucmd()
.args(&["10777", "file"])
.fails_with_code(1)
.stderr_is(
// spell-checker:disable-next-line
"chmod: mode is too large (10777 > 7777)\n",
);
// test around the boundary of the acceptable octal mode
scenario
.ucmd()
.args(&["10000", "file"])
.fails_with_code(1)
.stderr_is(
// spell-checker:disable-next-line
"chmod: mode is too large (10000 > 7777)\n",
);
scenario.ucmd().args(&["7777", "file"]).succeeds();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the BSD error is only coming from this line, it should be okay to disable this specifically for BSD or do something like this:

// Use a directory for 7777 test since sticky bit (0o1000) on files requires root on BSD systems
at.mkdir("dir");
scenario.ucmd().args(&["7777", "dir"]).succeeds();

}

#[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_ugo_copy() {
Expand Down
Loading