diff --git a/src/uucore/src/lib/features/mode.rs b/src/uucore/src/lib/features/mode.rs index d562f1fe038..5424e8985f7 100644 --- a/src/uucore/src/lib/features/mode.rs +++ b/src/uucore/src/lib/features/mode.rs @@ -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, diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index 18c180bd05a..7e6610934b4 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -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(); +} + #[test] #[allow(clippy::unreadable_literal)] fn test_chmod_ugo_copy() {