Skip to content

Commit

Permalink
fix: linux canonicalization checks
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Jul 18, 2024
1 parent d80d0ce commit 1380b23
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ext/fs/std_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,9 @@ fn open_with_access_check(
let is_windows_device_path = cfg!(windows)
&& path_bytes.starts_with(br"\\.\")
&& !path_bytes.contains(&b':');
// On Linux, /proc may contain magic links that we don't want to resolve
let is_linux_special_path =
cfg!(target_os = "linux") && path.starts_with("/proc");
let path = if is_windows_device_path {
// On Windows, normalize_path doesn't work with device-prefix-style
// paths. We pass these through.
Expand All @@ -1068,9 +1071,8 @@ fn open_with_access_check(
normalize_path(cwd.join(path))
};
(*access_check)(false, &path, &options)?;
// On Linux, /proc may contain magic links that we don't want to resolve
let needs_canonicalization = !is_windows_device_path
&& (!cfg!(target_os = "linux") || path.starts_with("/proc"));
let needs_canonicalization =
!is_windows_device_path && !is_linux_special_path;
let path = if needs_canonicalization {
match path.canonicalize() {
Ok(path) => path,
Expand Down

0 comments on commit 1380b23

Please sign in to comment.