From 1dd478aeb2c865d673a4b9a83435d9fa482783a7 Mon Sep 17 00:00:00 2001 From: JADella94 <48160118+BoiledElectricity@users.noreply.github.com> Date: Tue, 16 Jun 2026 16:22:02 -0400 Subject: [PATCH] fix(vpn): handle non-file url on openvpn import So openvpn import called to_file_path().unwrap(), which panics when the file picker hands back a non-file:// url (sandboxed portal, etc). the wireguard branch right above already handles this gracefully, so do the same: return a Message::Error with a new OpenVpnConfigPath kind instead of crashing. Fixes #1896 - [x] I have disclosed use of any AI generated code in my commit messages. - If you are using an LLM, and do not fully understand the changes it is making to the code base, do not create a PR. - In our experience, AI generated code often results in overly complex code that lacks enough context for a proper fix or feature inclusion. This results in considerably longer code reviews. Due to this, AI authored or partially authored PRs may be closed without comment. - [x] I understand these changes in full and will be able to respond to review comments. - [x] My change is accurately described in the commit message. - [x] My contribution is tested and working as described. - [x] I have read the [Developer Certificate of Origin](https://developercertificate.org/) and certify my contribution under its conditions. Signed-off-by: James A DellaMorte Co-authored-by: James A DellaMorte --- cosmic-settings/src/pages/networking/vpn/mod.rs | 12 ++++++++++-- i18n/en/cosmic_settings.ftl | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cosmic-settings/src/pages/networking/vpn/mod.rs b/cosmic-settings/src/pages/networking/vpn/mod.rs index 4e8c150..ff85a8f 100644 --- a/cosmic-settings/src/pages/networking/vpn/mod.rs +++ b/cosmic-settings/src/pages/networking/vpn/mod.rs @@ -95,6 +95,7 @@ pub enum ErrorKind { ConnectionEditor, ConnectionSettings, DbusConnection, + OpenVpnConfigPath, UpdatingState, WireGuardConfigPath, WireGuardDevice, @@ -109,6 +110,7 @@ impl ErrorKind { ErrorKind::ConnectionEditor => fl!("vpn-error", "connection-editor"), ErrorKind::ConnectionSettings => fl!("vpn-error", "connection-settings"), ErrorKind::DbusConnection => fl!("dbus-connection-error"), + ErrorKind::OpenVpnConfigPath => fl!("vpn-error", "openvpn-config-path"), ErrorKind::UpdatingState => fl!("vpn-error", "updating-state"), ErrorKind::WireGuardConfigPath => fl!("vpn-error", "wireguard-config-path"), ErrorKind::WireGuardDevice => fl!("vpn-error", "wireguard-device"), @@ -1199,8 +1201,14 @@ fn add_network() -> Task { return Message::AddWireGuardDevice(device, filename.to_owned(), path); } else { - super::nm_add_vpn_file("openvpn", response.url().to_file_path().unwrap()) - .await + let Ok(path) = response.url().to_file_path() else { + return Message::Error( + ErrorKind::OpenVpnConfigPath, + fl!("vpn-error", "openvpn-config-path-desc"), + ); + }; + + super::nm_add_vpn_file("openvpn", path).await }; match result { diff --git a/i18n/en/cosmic_settings.ftl b/i18n/en/cosmic_settings.ftl index ac509cd..0edc525 100644 --- a/i18n/en/cosmic_settings.ftl +++ b/i18n/en/cosmic_settings.ftl @@ -198,6 +198,8 @@ vpn-error = VPN Error .connect = Failed to connect to VPN .connection-editor = Connection editor failed .connection-settings = Failed to get settings for active connections + .openvpn-config-path = Invalid file path for OpenVPN config + .openvpn-config-path-desc = Chosen file must be on a local file system. .updating-state = Failed to update network manager state .wireguard-config-path = Invalid file path for WireGuard config .wireguard-config-path-desc = Chosen file must be on a local file system.