From 02eb2132aca8d7814fdaacbddc8b8373e110f0b7 Mon Sep 17 00:00:00 2001 From: Oakchris1955 <80592203+Oakchris1955@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:28:29 +0300 Subject: [PATCH] fix: don't expose the `.` & `..` entries to the end user --- src/fat/fs.rs | 4 +++- src/path.rs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fat/fs.rs b/src/fat/fs.rs index 0d1e283..c964f43 100644 --- a/src/fat/fs.rs +++ b/src/fat/fs.rs @@ -1,6 +1,6 @@ use super::*; -use crate::{error::*, io::prelude::*, path::PathBuf, time::*, utils}; +use crate::{error::*, io::prelude::*, path::PathBuf, time::*, utils, SPECIAL_ENTRIES}; use core::{cmp, ops}; @@ -1315,6 +1315,8 @@ where Ok(entries .into_iter() .filter(|x| self.filter.filter(x)) + // we shouldn't expose the special entries to the user + .filter(|x| !SPECIAL_ENTRIES.contains(&x.name.as_str())) .map(|rawentry| { let mut entry_path = path.clone(); diff --git a/src/path.rs b/src/path.rs index f9b6bf2..2d0aa34 100644 --- a/src/path.rs +++ b/src/path.rs @@ -29,6 +29,9 @@ pub const RESERVED_FILENAMES: &[&str] = &[ "COM8", "COM9", "COM¹", "COM²", "COM³", "LPT0", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "LPT¹", "LPT²", "LPT³", ]; +/// Except for the root directory, each directory must contain +/// the following (two) entries at the beginning of the directory +pub(crate) const SPECIAL_ENTRIES: &[&str] = &[".", ".."]; /// Check whether a [`PathBuf`] is forbidden for use in filenames or directory names fn is_forbidden(pathbuf: &PathBuf) -> bool {