From 3ab82f9a665918d237310b3fa9d48da5f5b46e58 Mon Sep 17 00:00:00 2001 From: Arcterus Date: Sat, 26 Nov 2016 17:16:11 -0800 Subject: [PATCH 1/4] uucore: read symlinked directories correctly in resolve_relative_path() --- src/uucore/fs.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/uucore/fs.rs b/src/uucore/fs.rs index 6f6ff3e2b..6c16c7177 100644 --- a/src/uucore/fs.rs +++ b/src/uucore/fs.rs @@ -26,6 +26,9 @@ pub fn resolve_relative_path<'a>(path: &'a Path) -> Cow<'a, Path> { for comp in path.components() { match comp { Component::ParentDir => { + if let Ok(p) = result.read_link() { + result = p; + } result.pop(); } Component::CurDir => (), From f5fce8dadbb7071030ff42d254b62fb658b415fc Mon Sep 17 00:00:00 2001 From: Arcterus Date: Mon, 28 Nov 2016 02:41:40 -0800 Subject: [PATCH 2/4] chgrp: detect bind mounted root --- src/chgrp/chgrp.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/chgrp/chgrp.rs b/src/chgrp/chgrp.rs index ff7ed6377..3613246d8 100644 --- a/src/chgrp/chgrp.rs +++ b/src/chgrp/chgrp.rs @@ -217,6 +217,21 @@ impl Chgrper { } } + #[cfg(windows)] + fn is_bind_root>(&self, root: P) -> bool { + false + } + + #[cfg(unix)] + fn is_bind_root>(&self, path: P) -> bool { + use std::os::unix::fs::MetadataExt; + + // FIXME: remove unwrap here + let given = std::fs::metadata(path).unwrap(); + let root = std::fs::metadata("/").unwrap(); + given.dev() == root.dev() && given.ino() == root.ino() + } + fn traverse>(&self, root: P) -> i32 { let follow_arg = self.dereference || self.bit_flag != FTS_PHYSICAL; let path = root.as_ref(); @@ -244,7 +259,7 @@ impl Chgrper { }; if let Some(p) = may_exist { - if p.parent().is_none() { + if p.parent().is_none() || self.is_bind_root(p) { show_info!("it is dangerous to operate recursively on '/'"); show_info!("use --no-preserve-root to override this failsafe"); return 1; From dc6ba887ba80c9cfe0fdcfa22bc301d572ea0a50 Mon Sep 17 00:00:00 2001 From: Arcterus Date: Wed, 30 Nov 2016 03:51:49 -0800 Subject: [PATCH 3/4] uucore: compile on Windows again --- src/uucore/fs.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/uucore/fs.rs b/src/uucore/fs.rs index 6c16c7177..6cc0d58da 100644 --- a/src/uucore/fs.rs +++ b/src/uucore/fs.rs @@ -14,7 +14,6 @@ use std::fs; use std::io::{Error, ErrorKind}; use std::io::Result as IOResult; use std::path::{Component, Path, PathBuf}; -#[cfg(unix)] use std::borrow::Cow; pub fn resolve_relative_path<'a>(path: &'a Path) -> Cow<'a, Path> { From 5d9437bcaf8c85c80a2cba9b66845003729a54cf Mon Sep 17 00:00:00 2001 From: Arcterus Date: Thu, 1 Dec 2016 06:02:58 -0800 Subject: [PATCH 4/4] chgrp: remove unwrap() in is_bind_root() --- src/chgrp/chgrp.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/chgrp/chgrp.rs b/src/chgrp/chgrp.rs index 3613246d8..dce25c9d0 100644 --- a/src/chgrp/chgrp.rs +++ b/src/chgrp/chgrp.rs @@ -219,17 +219,18 @@ impl Chgrper { #[cfg(windows)] fn is_bind_root>(&self, root: P) -> bool { + // TODO: is there an equivalent on Windows? false } #[cfg(unix)] fn is_bind_root>(&self, path: P) -> bool { - use std::os::unix::fs::MetadataExt; - - // FIXME: remove unwrap here - let given = std::fs::metadata(path).unwrap(); - let root = std::fs::metadata("/").unwrap(); - given.dev() == root.dev() && given.ino() == root.ino() + if let (Ok(given), Ok(root)) = (fs::metadata(path), fs::metadata("/")) { + given.dev() == root.dev() && given.ino() == root.ino() + } else { + // FIXME: not totally sure if it's okay to just ignore an error here + false + } } fn traverse>(&self, root: P) -> i32 {