diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-02-02 14:04:41 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-02-02 17:01:32 +0100 |
| commit | c9dbda702b4251d103871fc0cff0f0b8a590cd4f (patch) | |
| tree | 0ee2ffd5328bd2521bceebcf334db6cf6dfacdbf /talpid-core | |
| parent | 02e02c71aaad1d5ac8785a19c938c69801d5476d (diff) | |
| download | mullvadvpn-c9dbda702b4251d103871fc0cff0f0b8a590cd4f.tar.xz mullvadvpn-c9dbda702b4251d103871fc0cff0f0b8a590cd4f.zip | |
Improve validation of excluded paths
Diffstat (limited to 'talpid-core')
| -rw-r--r-- | talpid-core/src/split_tunnel/windows/windows.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/talpid-core/src/split_tunnel/windows/windows.rs b/talpid-core/src/split_tunnel/windows/windows.rs index 6ae2ce7c98..7000211bba 100644 --- a/talpid-core/src/split_tunnel/windows/windows.rs +++ b/talpid-core/src/split_tunnel/windows/windows.rs @@ -8,7 +8,7 @@ use std::{ ffi::{OsStrExt, OsStringExt}, io::{AsRawHandle, RawHandle}, }, - path::Path, + path::{Component, Path}, ptr, }; use winapi::{ @@ -116,9 +116,10 @@ pub fn get_device_path<T: AsRef<Path>>(path: T) -> Result<OsString, io::Error> { return get_final_path_name_by_handle(file.as_raw_handle()); } - let drive_comp = path.as_ref().components().next(); - let drive = match drive_comp { - Some(std::path::Component::Prefix(prefix)) => prefix.as_os_str(), + let mut components = path.as_ref().components(); + let drive_comp = components.next(); + let drive = match (drive_comp, components.next()) { + (Some(Component::Prefix(prefix)), Some(Component::RootDir)) => prefix.as_os_str(), _ => { return Err(io::Error::new( io::ErrorKind::InvalidInput, @@ -131,7 +132,9 @@ pub fn get_device_path<T: AsRef<Path>>(path: T) -> Result<OsString, io::Error> { let suffix = path .as_ref() .strip_prefix(drive_comp.unwrap()) - .expect("path missing own component"); + .map_err(|_error| { + io::Error::new(io::ErrorKind::InvalidInput, "path missing own component") + })?; new_path.push(suffix); Ok(new_path) |
