diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-06-15 17:54:20 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-06-15 17:54:20 +0200 |
| commit | cae28313e16996a5a3b79672384cdb14627f2a0b (patch) | |
| tree | 49feed27cd978d276b12d6dba995bf5d8034e934 | |
| parent | e8941bec667e9244be4f6840f0708c3d635449a1 (diff) | |
| parent | 11d2a82be24709e11edbf29b41b965443a156be1 (diff) | |
| download | mullvadvpn-cae28313e16996a5a3b79672384cdb14627f2a0b.tar.xz mullvadvpn-cae28313e16996a5a3b79672384cdb14627f2a0b.zip | |
Merge branch 'redact-dev-path-logs'
| -rw-r--r-- | mullvad-problem-report/src/lib.rs | 46 | ||||
| -rw-r--r-- | talpid-core/src/split_tunnel/windows/driver.rs | 5 |
2 files changed, 45 insertions, 6 deletions
diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs index b5fdadc2fe..829646fb91 100644 --- a/mullvad-problem-report/src/lib.rs +++ b/mullvad-problem-report/src/lib.rs @@ -420,10 +420,7 @@ impl ProblemReport { } fn redact_home_dir(input: &str) -> Cow<'_, str> { - match dirs_next::home_dir() { - Some(home) => Cow::from(input.replace(home.to_string_lossy().as_ref(), "~")), - None => Cow::from(input), - } + redact_home_dir_inner(input, dirs_next::home_dir()) } fn redact_network_info(input: &str) -> Cow<'_, str> { @@ -505,6 +502,32 @@ impl ProblemReport { } } +fn redact_home_dir_inner(input: &str, home_dir: Option<PathBuf>) -> Cow<'_, str> { + match home_dir { + Some(home) => { + let out = input.replace(home.to_string_lossy().as_ref(), "~"); + + // On Windows, redact the prefix of any path that contains \Users\{user}. + #[cfg(target_os = "windows")] + { + let mut home = home; + let prefix = home.components().next(); + if let Some(prefix @ std::path::Component::Prefix(_)) = prefix.as_ref() { + home = home.strip_prefix(prefix).unwrap().to_path_buf(); + } + let expr = format!(r"[\w\\]+{}", regex::escape(&home.display().to_string())); + let regex = Regex::new(&expr).unwrap(); + + Cow::Owned(regex.replace_all(&out, "~").to_string()) + } + + #[cfg(not(target_os = "windows"))] + Cow::from(out) + } + None => Cow::from(input), + } +} + fn build_mac_regex() -> String { let octet = "[[:xdigit:]]{2}"; // 0 - ff @@ -651,6 +674,21 @@ mod tests { } #[test] + #[cfg(windows)] + fn redacts_home_dir() { + let assert_redacts_home_dir = |home_dir, test_str| { + let input = format!(r"pre {}\remaining\path post", test_str); + let actual = redact_home_dir_inner(&input, Some(PathBuf::from(home_dir))); + assert_eq!(r"pre ~\remaining\path post", actual); + }; + + let home_dir = r"C:\Users\user"; + + assert_redacts_home_dir(home_dir, r"\Device\HarddiskVolume1\Users\user"); + assert_redacts_home_dir(home_dir, r"C:\Users\user"); + } + + #[test] fn doesnt_redact_not_guid() { assert_does_not_redact("23123ab-12ab-89cd-45ef-012345678901"); assert_does_not_redact("GGGGGGGG-GGGG-GGGG-GGGG-GGGGGGGGGGGG"); diff --git a/talpid-core/src/split_tunnel/windows/driver.rs b/talpid-core/src/split_tunnel/windows/driver.rs index 6b6b2b2ea7..2b612ff085 100644 --- a/talpid-core/src/split_tunnel/windows/driver.rs +++ b/talpid-core/src/split_tunnel/windows/driver.rs @@ -18,6 +18,7 @@ use std::{ fs::OpenOptionsExt, io::{AsRawHandle, RawHandle}, }, + path::Path, ptr, time::Duration, }; @@ -354,7 +355,7 @@ impl DeviceHandle { log::debug!( "{}\nPath: {}", error.display_chain_with_msg("Ignoring path on unmounted volume"), - app.as_ref().to_string_lossy() + Path::new(app.as_ref()).display() ); } Err(error) => return Err(error), @@ -368,7 +369,7 @@ impl DeviceHandle { log::debug!("Excluded device paths:"); for path in &device_paths { - log::debug!(" {:?}", path); + log::debug!(" {}", Path::new(&path).display()); } let config = make_process_config(&device_paths); |
