Skip to content

Commit

Permalink
Add missing reserved file names (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-daniel authored Nov 5, 2024
1 parent 24b9367 commit dcc3818
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cap-primitives/src/windows/fs/open_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ pub(crate) fn open_impl(
) -> io::Result<fs::File> {
// Windows reserves several special device paths. Disallow opening any
// of them.
// See: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
if let Some(stem) = path.file_stem() {
if let Some(stemstr) = stem.to_str() {
match stemstr.to_uppercase().as_str() {
"CON" | "PRN" | "AUX" | "NUL" | "COM0" | "COM1" | "COM2" | "COM3" | "COM4"
| "COM5" | "COM6" | "COM7" | "COM8" | "COM9" | "LPT0" | "LPT1" | "LPT2"
| "LPT3" | "LPT4" | "LPT5" | "LPT6" | "LPT7" | "LPT8" | "LPT9" => {
| "COM5" | "COM6" | "COM7" | "COM8" | "COM9" | "COM¹" | "COM²" | "COM³"
| "LPT0" | "LPT1" | "LPT2" | "LPT3" | "LPT4" | "LPT5" | "LPT6" | "LPT7"
| "LPT8" | "LPT9" | "LPT¹" | "LPT²" | "LPT³" => {
return Err(io::Error::from_raw_os_error(ERROR_FILE_NOT_FOUND as i32));
}
_ => {}
Expand Down

0 comments on commit dcc3818

Please sign in to comment.