Skip to content

Redox: Use O_NOFOLLOW for lstat() #43056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2017
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
5 changes: 4 additions & 1 deletion src/libstd/sys/redox/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,10 @@ pub fn stat(p: &Path) -> io::Result<FileAttr> {
}

pub fn lstat(p: &Path) -> io::Result<FileAttr> {
stat(p)
let fd = cvt(syscall::open(p.to_str().unwrap(),
syscall::O_CLOEXEC | syscall::O_STAT | syscall::O_NOFOLLOW))?;
Copy link
Member

Choose a reason for hiding this comment

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

FWIW this should probably also specify O_RDONLY to obey posix (since redox seems to be posixish).

(it's an interesting dilemma whether redox should reject that syscall as-is - it's technically invalid, but linux would accept it because O_RDONLY is defined as 0, so is always implicit. In redox it's defined as 1, so there's a choice between correctness and Linux program compatibility)

Copy link
Contributor

@jackpot51 jackpot51 Jul 8, 2017

Choose a reason for hiding this comment

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

False. O_STAT in Redox allows a file handle to be opened on a file without read permission, if the user has the ability to read the directory. This file handle can only be used for things like fstat.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see O_STAT is not posix, I guess that justifies my 'ish' in 'posixish'. Thanks for the clarification.

let file = File(FileDesc::new(fd));
file.file_attr()
}

pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/redox/syscall/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub const O_EXCL: usize = 0x0800_0000;
pub const O_DIRECTORY: usize = 0x1000_0000;
pub const O_STAT: usize = 0x2000_0000;
pub const O_SYMLINK: usize = 0x4000_0000;
pub const O_NOFOLLOW: usize = 0x8000_0000;
pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR;

pub const SEEK_SET: usize = 0;
Expand Down