summaryrefslogtreecommitdiffstats
path: root/src/mailcap.rs
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-05-28 16:27:02 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-05-28 21:02:49 +0300
commitbd404e69374e8b732effa450a10f4a903a206850 (patch)
tree0ae7d25a2a3cb77414cf51277a9322f8f5ef4f01 /src/mailcap.rs
parentbfff0e4feb79495264cf6f0d8d12d9823b50d51d (diff)
Execute user shell commands with /bin/sh
Execute user provided command invocations $CMD such as `editor_cmd` with `/bin/sh` as `/bin/sh -c "$CMD" Previously, user commands were split by whitespace which must trigger erroneous behavior if quotes are involved.
Diffstat (limited to 'src/mailcap.rs')
-rw-r--r--src/mailcap.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/mailcap.rs b/src/mailcap.rs
index 5bcd92d2..310eb884 100644
--- a/src/mailcap.rs
+++ b/src/mailcap.rs
@@ -21,7 +21,6 @@
/*! Find mailcap entries to execute attachments.
*/
-use crate::split_command;
use crate::state::Context;
use crate::types::{create_temp_file, ForkType, UIEvent};
use melib::attachments::decode;
@@ -180,10 +179,15 @@ impl MailcapEntry {
{
context.input_kill();
}
+ let cmd_string = format!("{} {}", cmd, args.join(" "));
+ melib::log(
+ format!("Executing: sh -c \"{}\"", cmd_string.replace("\"", "\\\"")),
+ melib::DEBUG,
+ );
if copiousoutput {
let out = if needs_stdin {
- let mut child = Command::new(cmd)
- .args(args)
+ let mut child = Command::new("sh")
+ .args(&["-c", &cmd_string])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
@@ -191,8 +195,8 @@ impl MailcapEntry {
child.stdin.as_mut().unwrap().write_all(&decode(a, None))?;
child.wait_with_output()?.stdout
} else {
- let child = Command::new(cmd)
- .args(args)
+ let child = Command::new("sh")
+ .args(&["-c", &cmd_string])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
@@ -213,8 +217,8 @@ impl MailcapEntry {
debug!(pager.wait_with_output()?.stdout);
} else {
if needs_stdin {
- let mut child = Command::new(cmd)
- .args(args)
+ let mut child = Command::new("sh")
+ .args(&["-c", &cmd_string])
.stdin(Stdio::piped())
.stdout(Stdio::inherit())
.spawn()?;
@@ -222,8 +226,8 @@ impl MailcapEntry {
child.stdin.as_mut().unwrap().write_all(&decode(a, None))?;
debug!(child.wait_with_output()?.stdout);
} else {
- let child = Command::new(cmd)
- .args(args)
+ let child = Command::new("sh")
+ .args(&["-c", &cmd_string])
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.spawn()?;