-
-
Notifications
You must be signed in to change notification settings - Fork 88
Handle absolute paths #306
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
e481679
f7746c8
fb92a8e
6e1fa7b
bdb5632
d5bc47a
99219ca
4d3a1fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -668,6 +668,39 @@ impl EncryptedFs { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // Must be given a path (as SecretString) and the root ino for the path | ||||||||
| // Parses the path for its components and checks if each component exists EXCLUDING the last one. | ||||||||
| // The last file/directory must be checked separately. | ||||||||
| // If given only a file/directory name returns them again. | ||||||||
| // When given a path, returns the file/directory name and the new ino | ||||||||
| async fn handle_path(&self, parent: u64, name: SecretString) -> FsResult<(u64, SecretString)> { | ||||||||
| let input = name.expose_secret().to_string(); | ||||||||
| let path = input.strip_prefix(".").unwrap_or(&input).to_owned(); | ||||||||
| let mut path_segments = vec![]; | ||||||||
| for segment in path.split("/") { | ||||||||
| if segment.is_empty() { | ||||||||
| continue; | ||||||||
| } | ||||||||
| let segment = SecretString::from_str(segment).unwrap(); | ||||||||
| path_segments.push(segment); | ||||||||
| } | ||||||||
| let file_name = path_segments | ||||||||
| .last() | ||||||||
| .ok_or_else(|| FsError::InvalidInput("No filename"))? | ||||||||
| .clone(); | ||||||||
| let mut current_ino: u64 = parent; | ||||||||
| if path_segments.len() > 1 { | ||||||||
| for segment in path_segments.iter().take(path_segments.len() - 1) { | ||||||||
| current_ino = self | ||||||||
| .find_by_name(current_ino, &segment.clone()) | ||||||||
| .await? | ||||||||
| .ok_or_else(|| FsError::InodeNotFound)? | ||||||||
| .ino; | ||||||||
| } | ||||||||
| } | ||||||||
| Ok((current_ino, file_name)) | ||||||||
| } | ||||||||
|
|
||||||||
| /// Create a new node in the filesystem | ||||||||
| #[allow(clippy::missing_panics_doc)] | ||||||||
| #[allow(clippy::missing_errors_doc)] | ||||||||
|
|
@@ -689,10 +722,10 @@ impl EncryptedFs { | |||||||
| if !self.exists(parent) { | ||||||||
| return Err(FsError::InodeNotFound); | ||||||||
| } | ||||||||
| if self.exists_by_name(parent, name)? { | ||||||||
| let (parent, name) = self.handle_path(parent, name.clone()).await?; | ||||||||
|
||||||||
| let (parent, name) = self.handle_path(parent, name.clone()).await?; | |
| let (parent, name) = self.handle_path(parent, name.clone()).await?; | |
| self.validate_filename(&name)?; |
Copilot
AI
Jul 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This TODO comment appears stale; either implement the missing logic here or remove it to keep the code clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider explicitly rejecting
".."segments (e.g. return an error) to avoid directory traversal and prevent unintended parent‐dir resolution.