Skip to content
Merged
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
28 changes: 28 additions & 0 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,34 @@ 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",
);
at.mkdir("dir");
scenario.ucmd().args(&["7777", "dir"]).succeeds();
}

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