From 4eed226e43370bf4759ed9f655e5fcf0546a9a3c Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Mon, 31 Mar 2014 20:07:22 +0200 Subject: shellexec: correct escaping of single quotes --- plugins/shellexec/shellexec.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'plugins/shellexec') diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c index 473fc1a7..3894b6b4 100644 --- a/plugins/shellexec/shellexec.c +++ b/plugins/shellexec/shellexec.c @@ -88,6 +88,24 @@ static int shx_exec_track_cmd (Shx_action_t *action, DB_playItem_t *it) { return -1; } strcat (cmd, "&"); + + // replace \' with '"'"' + size_t l = strlen (cmd); + size_t remaining = _POSIX_ARG_MAX - l - 1; + for (int i = 0; cmd[i]; i++) { + if (cmd[i] == '\\' && cmd[i+1] == '\'' && remaining >= 3) { + memmove (&cmd[i+5], &cmd[i+2], l - i + 1 - 2); + memcpy (&cmd[i], "'\"'\"'", 5); + l += 3; + remaining -= 3; + i += 5; + } + else if (remaining < 3) { + fprintf (stderr, "shellexec: command is too long.\n"); + return -1; + } + } + trace ("%s\n", cmd); res = system (cmd); return 0; -- cgit v1.2.3