From 5403d30d7358ad968b1d53595258d153c77548a4 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Sun, 22 Apr 2012 22:38:13 +0200 Subject: [PATCH] Always use a temp file when passing input to shell commands to avoid quoting issues. The "echo 'input' | command" apprach doesn't work reliably for input containing "\n". Fixed giving up the pipe approach and just using a temp file always. --- moo/plugins/usertools/moocommand-exe.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/moo/plugins/usertools/moocommand-exe.c b/moo/plugins/usertools/moocommand-exe.c index 4c3225ee..a1b4353d 100644 --- a/moo/plugins/usertools/moocommand-exe.c +++ b/moo/plugins/usertools/moocommand-exe.c @@ -248,26 +248,13 @@ make_cmd (const char *base_cmd_line, if (!input_len) return g_strdup (base_cmd_line); - if (input_len < 2048) + char *tmp_file = save_temp (input, input_len); + + if (tmp_file) { - char *quoted; - - quoted = g_shell_quote (input); - g_return_val_if_fail (quoted != NULL, NULL); - - cmd_line = g_strdup_printf ("echo -n %s | ( %s )", quoted, base_cmd_line); - g_free (quoted); - } - else - { - char *tmp_file = save_temp (input, input_len); - - if (tmp_file) - { - cmd_line = g_strdup_printf ("( %s ) < '%s' ; rm '%s'", - base_cmd_line, tmp_file, tmp_file); - g_free (tmp_file); - } + cmd_line = g_strdup_printf ("( %s ) < '%s' ; rm '%s'", + base_cmd_line, tmp_file, tmp_file); + g_free (tmp_file); } return cmd_line;