diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-10-19 14:32:46 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-10-19 14:32:46 +0200 |
| commit | 801aba750a7e282ce965ae99ac26ae0006f579b3 (patch) | |
| tree | e592da2190ee8b9939a2593bd6ce22dca69fa5af | |
| parent | 9a7f29d3dc55133b0bf2b82001310e61b0d3fef5 (diff) | |
| download | mullvadvpn-801aba750a7e282ce965ae99ac26ae0006f579b3.tar.xz mullvadvpn-801aba750a7e282ce965ae99ac26ae0006f579b3.zip | |
Escape shell arguments nicer
| -rw-r--r-- | talpid-core/src/process/openvpn.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/talpid-core/src/process/openvpn.rs b/talpid-core/src/process/openvpn.rs index 0c534f63b9..0eb5ec953e 100644 --- a/talpid-core/src/process/openvpn.rs +++ b/talpid-core/src/process/openvpn.rs @@ -189,25 +189,22 @@ impl fmt::Display for OpenVpnCommand { /// Format the program and arguments of an `OpenVpnCommand` for display. Any non-utf8 data /// is lossily converted using the utf8 replacement character. fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.write_str(&self.openvpn_bin.to_string_lossy())?; - for arg in self.get_arguments().iter().map(|arg| arg.to_string_lossy()) { - write_argument(fmt, &arg)?; + shell_escape(fmt, &self.openvpn_bin.to_string_lossy())?; + for arg in &self.get_arguments() { + fmt.write_str(" ")?; + shell_escape(fmt, &arg.to_string_lossy())?; } Ok(()) } } -fn write_argument(fmt: &mut fmt::Formatter, arg: &str) -> fmt::Result { - fmt.write_str(" ")?; - let quote = arg.contains(char::is_whitespace); - if quote { - fmt.write_str("\"")?; - } - fmt.write_str(arg)?; - if quote { - fmt.write_str("\"")?; - } - Ok(()) +fn shell_escape(fmt: &mut fmt::Formatter, arg: &str) -> fmt::Result { + let quote = if arg.contains(char::is_whitespace) { + "\"" + } else { + "" + }; + write!(fmt, "{}{}{}", quote, arg, quote) } |
