From 13238344bf01d7927811df8f549c6075b539db9d Mon Sep 17 00:00:00 2001 From: pjht Date: Fri, 8 Nov 2024 14:54:01 -0600 Subject: [PATCH] Only allow directory reads at the root level --- src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a2044f1..d04034d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,15 @@ impl fs_rpc::Server for Serv { Ok((Some(device_pid), fd)) } - fn open_dir(&self, _path: &std::path::Path, _mount_id: u64) -> Result<(Option, u64), Errno> { + fn open_dir(&self, path: &std::path::Path, _mount_id: u64) -> Result<(Option, u64), Errno> { + let path = path.to_str().ok_or(Errno::EINVALDAT)?; + if !path.is_empty() { + if self.devices.read().contains_key(path) { + return Err(Errno::ENOTDIR); + } else { + return Err(Errno::ENOENT); + } + } let entries = self.devices.read().keys().cloned().collect::>(); self.dirs .write()