From a519f0a50326ac94c33deef06d1453f6353d765c Mon Sep 17 00:00:00 2001 From: nulldev Date: Mon, 14 Mar 2022 03:52:30 -0400 Subject: [PATCH] Fix handling of backslashes in profiles.ini --- Cargo.lock | 71 +++++++++++-------------------------------------- Cargo.toml | 2 +- src/profiles.rs | 20 ++++++++++---- 3 files changed, 32 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec34c90..7b1495c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,14 @@ version = 3 [[package]] name = "ahash" -version = "0.4.7" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.3", + "once_cell", + "version_check", +] [[package]] name = "arrayref" @@ -163,12 +168,9 @@ dependencies = [ [[package]] name = "dlv-list" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b391911b9a786312a10cb9d2b3d0735adfd5a8113eb3648de26a75e91b0826c" -dependencies = [ - "rand 0.7.3", -] +checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" [[package]] name = "fern" @@ -262,9 +264,9 @@ checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" [[package]] name = "hashbrown" -version = "0.9.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" dependencies = [ "ahash", ] @@ -381,9 +383,9 @@ checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "ordered-multimap" -version = "0.3.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485" +checksum = "7b476c5fc0aad16f8b8d74e7df9da1813731fae300f7a923713c4c591905ff50" dependencies = [ "dlv-list", "hashbrown", @@ -438,19 +440,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - [[package]] name = "rand" version = "0.8.3" @@ -473,16 +462,6 @@ dependencies = [ "rand_core 0.3.1", ] -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", -] - [[package]] name = "rand_chacha" version = "0.3.0" @@ -508,15 +487,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", -] - [[package]] name = "rand_core" version = "0.6.2" @@ -535,15 +505,6 @@ dependencies = [ "rand_core 0.3.1", ] -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - [[package]] name = "rand_hc" version = "0.3.0" @@ -662,11 +623,11 @@ dependencies = [ [[package]] name = "rust-ini" -version = "0.16.1" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55b134767a87e0b086f73a4ce569ac9ce7d202f39c8eab6caa266e2617e73ac6" +checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "ordered-multimap", ] diff --git a/Cargo.toml b/Cargo.toml index 41b2a72..9b53e25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ test = false bench = false [dependencies] -rust-ini = "0.16" +rust-ini = "0.18.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_cbor = "0.11.1" diff --git a/src/profiles.rs b/src/profiles.rs index 7bc9397..454d632 100644 --- a/src/profiles.rs +++ b/src/profiles.rs @@ -3,7 +3,7 @@ use serde_json::Value; use serde::{Deserialize, Serialize}; use crate::config::Config; use std::path::{PathBuf, Path}; -use ini::Ini; +use ini::{EscapePolicy, Ini, ParseOption}; use std::io; use std::fs::OpenOptions; use crate::storage::{avatar_data_path, options_data_path}; @@ -58,8 +58,18 @@ pub enum ReadProfilesError { BadOptionsStoreFormat(serde_json::Error) } +const MOZ_INI_PARSE_OPTION: ParseOption = ParseOption { + enabled_quote: false, + enabled_escape: false +}; +// Firefox doesn't escape backslashes, emojis, equal signs, and even quotation marks... +// Does it even escape anything at all? +// Note that this will cause problems if users put newlines or null bytes in their string +// But we can't really do anything about this... +const MOZ_INI_ESCAPE_POLICY: EscapePolicy = EscapePolicy::Nothing; + pub fn read_profiles(config: &Config, config_dir: &Path) -> Result { - let profiles_conf = Ini::load_from_file(config.profiles_ini_path()) + let profiles_conf = Ini::load_from_file_opt(config.profiles_ini_path(), MOZ_INI_PARSE_OPTION) .map_err(ReadProfilesError::IniError)?; let avatar_data: AvatarData = OpenOptions::new() @@ -212,13 +222,13 @@ pub fn write_profiles(config: &Config, config_dir: &Path, state: &ProfilesIniSta } } - if let Err(e) = new_ini.write_to_file(config.profiles_ini_path()) { + if let Err(e) = new_ini.write_to_file_policy(config.profiles_ini_path(), MOZ_INI_ESCAPE_POLICY) { return Err(WriteProfilesError::WriteIniError(e)) } // Write install INI if let Some(default_profile_path) = default_profile_path { - let installs_conf = Ini::load_from_file(config.installs_ini_path()); + let installs_conf = Ini::load_from_file_opt(config.installs_ini_path(), MOZ_INI_PARSE_OPTION); if let Ok(mut installs_conf) = installs_conf { for (sec, prop) in &mut installs_conf { if let Some(sec) = sec { @@ -228,7 +238,7 @@ pub fn write_profiles(config: &Config, config_dir: &Path, state: &ProfilesIniSta } } } - if let Err(e) = installs_conf.write_to_file(config.installs_ini_path()) { + if let Err(e) = installs_conf.write_to_file_policy(config.installs_ini_path(), MOZ_INI_ESCAPE_POLICY) { log::warn!("Failed to write installs.ini: {:?}", e); } }