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
7 changes: 7 additions & 0 deletions src/find/matchers/perm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ mod parsing {
}

pub fn parse_mode(pattern: &str, for_dir: bool) -> Result<u32, Box<dyn Error>> {
// GNU rejects the old `-perm +MODE` octal form; a leading + needs a symbolic mode.
if let Some(rest) = pattern.strip_prefix('+') {
if rest.contains(|c: char| c.is_ascii_digit()) {
return Err(From::from(format!("invalid mode '+{rest}'")));
}
}

let mode = if pattern.contains(|c: char| c.is_ascii_digit()) {
parse_numeric(0, pattern, for_dir)?
} else {
Expand Down
15 changes: 15 additions & 0 deletions tests/test_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,21 @@ fn find_perm() {
ucmd().args(&["-perm", "u=g"]).succeeds();
}

#[cfg(unix)]
#[test]
fn find_perm_plus_octal_is_rejected() {
// GNU find rejects the deprecated `-perm +MODE` octal form; only symbolic
// modes may follow a leading `+`.
ucmd()
.args(&["-perm", "+644"])
.fails()
.stderr_contains("invalid mode '+644'");
ucmd()
.args(&["-perm", "+0"])
.fails()
.stderr_contains("invalid mode '+0'");
}

#[cfg(unix)]
#[test]
fn find_inum() {
Expand Down
Loading